First Things First......................
______________
First thing to do is to include the header file fstream.h
like this...#include<fstream.h>
2)next thing is to declare the stream object example
fstream skuddy;
3)third thing is to use open method to initialize it
skuddy.open("filename",filemode);
where filename stands for a valid file location & filemode for
the below
ios::in -open for input
ios:
ut-open for output
ios::binary-open in binary mode
ios::app-open for appending
ios::nocreate-do not create the file if it does not exist
ios::noreplace-ditto,do not replace(if the file exists)
ios::trunc-destroys data in existing file
phew! thats it. u can input & output as shown in the following
program
#include<fstream.h>
#include<conio.h>
void main()
{
int n;
fstream skuddy;
skuddy.open("inter.txt",ios:
ut);
cin>>n;
skuddy<<n;
skuddy.close();
}
اين برنامه را من چك كردم. چند خط كد بالا را. كارش اينه كه يك عدد از كاربر مي خواهد و بعد يك فايل تكست ايجاد مي كنه به نام اينتر و آن عدد را در آن يادداشت مي كنه.
now read inter.txt with a text editor u will find an integer value
similaly u can output as..
#include<fstream.h>
#include<conio.h>
void main()
{
int n;
char ch;
fstream skuddy;
skuddy.open("inter.txt",ios::in);
skuddy>>n;
cout<<n;
getch();
skuddy.close();
}
كاملش را مي توانيد بگيريد.