Reputation: 19
fstream file(file_1.c_str(), ios::out | ios::in | ios::ate); //convert string to const char*
Error if File does not exist. if ( ! file ) = true
fstream file(file_1.c_str(), ios::out | ios::in | ios::app); //convert string to const char*
using ios::app
seekg
& seekp
functions not working. file.seekg(4, ios_base::beg);
I would like to have:
Upvotes: -1
Views: 284
Reputation: 16
If I understand you correctly, you need something like this:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
string name;
std::cin>>name;
std::ofstream file (name.c_str());
outfile << "Text in file." << std::endl;
file.close();
return 0;
}
Upvotes: 0