C++ Text File Write Character by Character

Description

C++ Text File Write Character by Character

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()//from w ww. j a  v a2  s .  c  o  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