-
As you should have noticed when you read the manual on c_str(), but didn't, the result of c_str() is not modifiable, so any attempt to add something at the end is doomed to failure. Also, when C++ says const, it means it, so it laughs at your attempt to remove the const condition.
Since c_str() is not modifiable, you have to add rpg to the string filenameo itself. And if you don't plan to keep the name around, then there's no good reason to not just put the call in the constructor (and it's what people will expect, too), like so:
Code:
std::ofstream output(filenameo.c_str());
-
The first problem is due to filename being a char* instead of a const char*. The second problem is due to you attempting to concatenate "rpg" to filename, but such concatenation using operator+ only works (correctly) on std::string. As such, just write:
Code:
std::string filename;
// ...
cin >> filename;
filename += "rpg";
std::ofstream output(filename.c_str());
Alternatively, you can write:
Code:
std::ofstream output((filename + "rpg").c_str());
But it may be better to concatenate the "rpg" to the string if you should need to reuse the filename, e.g., to show the user what file was opened.