Opening files using open()
The function open() can be used to open multiple files that use the same stream object.
Syntax:
File_stream object streamobject;
Stream_object. Open(“file_name”);
Ofstream obj1;
Obj1. open(“employee”);
#include<>
#include<>
#include<>
main()
{
char string[120];
clrscr();
cout<<”Enter an string”;
cin>> string;
int len=strlen(string);
cout<< len<<”\n”;
fstream file;
file.open(“samp.txt”,ios::in ios::out);
for(int i=0;i< len;i++)
{
file.put(string[i]);
}
file.seekg(0);
char ch[90];
for(i=0;i< len;i++)
{
file.get(ch[i]);
cout<< ch[i];
}
file.close();
getch();
}
No comments:
Post a Comment