Categories

Subscribe via Email

Enter your email address to subscribe and receive notifications of new content by email.

Write text to a file

This example uses streams to write text to a file

#include<iostream.h>
#include<fstream.h>

int main()

{
// first lets output to a file
ofstream fout(“sample.txt”);
fout << “programmershelp” << endl;
fout.close();
char str[20];
//read in the file
ifstream fin(“sample.txt”);
fin >> str;
fin.close();
//display sample.txt contents
cout << “data read from file: ” << str << endl;
return 0;
}

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare

Leave a Reply

  

  

  


*

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>