Cara baca file di C++
#include <iostream.h>
#include<fstream.h>
using namespace std;
int baca()
{
char str[24];
fstream file(“c:\\Users\Gerwin\Desktop\PBO\proyek\kode.txt”,ios::in);
//C:\Users\Gerwin\Desktop\PBO\proyek
while(!file.eof())
{
file.getline(str,24);
cout<<str;
}
file.close();
return 0;
}
DEV C++
#include <iostream.h>
#include<fstream.h>
using namespace std;
int main()
{
char str[1000];
fstream file(“kode.txt”,ios::in);//membaca file
while(!file.eof())
{
file.getline(str,1000);
cout<<str;
}
file.close();
return 0;
}
sintak fstream ini dapat digunakan untuk membaca file /input operasi, tapi harus ada #include <fstream.h>
Explore posts in the same categories: Kuliah