101
{ USER }
posts: 55
last: 09-Apr-2008
TITLE: Outputting text to a file
DESCRIPTION: Write text to a file
Submitted: 09-Apr-2008 08:38:07 ( 21w 5d 2h ago ) Language: C++ (*.cpp *.h)
Views: 193 Lines of Code: 36 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Intermediate
Bookmark
/* Author: 101
   Date: 09-04-2008
   Filename: 
   Description: Write text to a file
   History: 
*/


#include <iostream.h>
#include <fstream.h>
const char *FILENAME = "myfile.txt";

int main() 
{
    //create output object associated w/ file

    ofstream fout(FILENAME);
    cout << "Enter your text: ";
    char str[100];
    cin >> str;

    //write the text to the file

    fout << "here is your text\n";
    fout <<str<<endl;
    //close file
    fout.close();
    
    ifstream fin(FILENAME);
    char ch;
    while (fin.get(ch))
    cout << ch;
    fin.close(); 
 
    return 0;
}