C++ ofstream put() Write Character to text file

Description

C++ ofstream put() Write Character to text file

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()/*from   w w  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;
}



PreviousNext

Related