/* Write to a file */
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream of(“test”,ios::app);
char name[30];
cout<<“Enter name:”<<endl;
cin>>name;
of<<name<<“\n”;
of.close();
return 0;
}
/* Read file */
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream ifs(“test”);
char name[30];
cout<<“File data:” <<endl;
ifs>>name;
while(ifs.eof() == 0){
cout << name <<” “;
ifs>>name;
}
ifs.close();
return 0;
}
/* Read as line */
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream ifs(“test”);
int SIZE = 80;
char name[SIZE];
cout<<“File data:” <<endl;
do{
ifs.getline(name,SIZE);
cout<< name <<endl;
}while(ifs.eof() == 0);
ifs.close();
return 0;
}
/* cursor movement */
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream of(“test”,ios::app);
char name[30];
cout<<“Enter name:”<<endl;
cin>>name;
of.seekp(-5,ios::cur);
of<<name<<“\n”;
of.close();
return 0;
}