#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
//Declaring file.
ofstream f;
string filename;
cout << "Please enter a file name to write: ";
getline( cin, filename );
//If you can also explain what .c_str() does here that would be awesome.
f.open( filename.c_str() );
f << "Hello world!\n";
f.close();
cout << "Good job! 'type' or 'cat' your new file to see what it says.\n";
return 0;
}
Aucun commentaire:
Enregistrer un commentaire