hey, im trying to write a program that will create a outfile and open it but the name of the file will be detimermind by a variable in the program. is there any way to do this? i want something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
// variables
string lastname;
int main(){
cout << "Enter your lastname:\n";
cin >> lastname;
outfile.open(lastname".txt"); /* <-- i need to get this to work to
finish my project any help would be
thanked.*/
std::fstream::open() takes (for some reason) a C string as its first parameter, and you're trying to pass an std::string.
Wrap the concatenation with parentheses and make a call to std::string::c_str(). It should look like (a+b).c_str().