C++ ofstream Save characters to file

Description

C++ ofstream Save characters to file

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()//www.  j  a v  a  2 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