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

Tinggalkan Balasan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Ubah )

Twitter picture

You are commenting using your Twitter account. Log Out / Ubah )

Facebook photo

You are commenting using your Facebook account. Log Out / Ubah )

Connecting to %s


Ikuti

Get every new post delivered to your Inbox.