//1. pengen bikin di txt
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<fstream.h>
void main()
{
ofstream file_out;
file_out.open("jajal1.txt"); //nama file txt
file_out<<"nama saya ardhi"; //isi baris ke 1
file_out<<"\nterimakasih sudah membaca"; //isi baris ke 2
file_out<<"\nbye..."; //isi baris ke 3
file_out.close();
}
output:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<fstream.h>
void main()
{
const maks=300;
char wadah[maks+1];
ifstream file_in;
file_in.open("jajal1.txt");
while(file_in)
{
file_in.getline(wadah, maks);
cout<<wadah<<endl;
}
file_in.close();
}
output:
//3. pengen nampilin di exe (rata kanan)
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<fstream.h>
void main()
{
const maks=300;
char wadah[maks+1];
ifstream file_in;
file_in.open("jajal1.txt");
while(file_in)
{
file_in.getline(wadah, maks);
cout<<setw(50)<<wadah<<endl; //biar rata kanan dikasih setw(terserah_berapa_karakter)
}
file_in.close();
}
output:
//4. pengen copy jajal1.txt ke jajal_new.txt (rata kiri)
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<fstream.h>
void main()
{
const maks=300;
char wadah[maks+1];
ifstream file_in;
ofstream file_out;
file_out.open("jajal_new.txt"); //bikin baru
file_in.open("jajal1.txt"); //ngambil dari jajal1.txt
while (!file_in.eof())
{
file_in.getline(wadah, maks);
file_out<<wadah<<endl;
}
file_in.close();
}
output:
//5. pengen copy jajal1.txt ke jajal_new.txt
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<fstream.h>
void main()
{
const maks=300;
char wadah[maks+1];
ifstream file_in;
ofstream file_out;
file_out.open("jajal_new.txt"); //bikin baru
file_in.open("jajal1.txt"); //ngambil dari jajal1.txt
while (!file_in.eof())
{
file_in.getline(wadah, maks);
file_out<<setw(50)<<wadah<<endl; //sama kayak no 3 tadi, tinggal dikasih setw
}
file_in.close();
}
output:
semoga penjelasan di atas dapat mudah dipahami ya ^^ thank you..
Sign up here with your email
3 komentar
Write komentarterimakasih sudah berkunjung mas fadly :)
ReplyMembantu saya dalam menyelesaikan tugas :D Terimakasih :)
Replyterimakasih sudah berkunjung ^^ sering sering mampir ya~ :D
ReplyConversionConversion EmoticonEmoticon