26 Nov 2019

  • November 26, 2019
  • Amitraj
C++ File I/O Operations on Characters

#include<iostream>
using namespace std;
#include<fstream>
#include<cstring>
int main()
{
char string[80];
cout<<"Enter a string:";
cin>>string;
int len=strlen(string);
fstream file;
cout<<"\n Opening the text file and storing data";
file.open("xyz.txt",ios::in|ios::out);
for(int i=0;i<len;i++)
file.put(string [i]);
file.seekg(0);
char ch;
cout<<"Reading the file contents:";
while(file.get(ch))
{
cout<<ch;
}
return 0;

}

OUTPUT:








Translate

Popular Posts