Save characters to file - C++ File Stream

C++ examples for File Stream:stream

Description

Save characters to file

Demo Code

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()/*from ww  w.  j  av  a  2 s .  co m*/
{
   string str = "this is a test test test";
   ofstream outfile("TEST.TXT");     //create file for output
   for(int j=0; j<str.size(); j++)   //for each character,
      outfile.put( str[j] );         //write it to file
   cout << "File written\n";
   return 0;
}

Result


Related Tutorials