Write,text,to,a,file,c++

Yavuz 9/19/2016 0

Write text to a file in C++

C++
#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;
}
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments