In option one, any user input with a space breaks the program. |
cin >>
is space-delimited. In order to put in a name with spaces, you have to use
getline.
1 2 3 4 5 6 7 8
|
string image_filename;
cout << "Enter image filename: ";
getline(cin, image_filename);
cin.ignore(); // ignore the remaining newline in the cin's buffer.
ofstream myfile;
myfile.open ("file.txt");
myfile << image_filename;
|
Decimal input for select an option menu still breaks the program |
n is an int. This means integer, {..., -2, -1, 0, 1, 2, 3...}. You can't put a floating-point number in an int. Why do you want to do this? All of your options are ints {1, 2, 3, 4, 5}.
Where is the file actually created |
If you only provide a name, the file is created in the same place that your program is being run from. On some IDEs, the "working directory" of execution is sometimes where your project file is, other times it might be in a bin/Debug or bin/Release folder.
Alternatively, you could choose to open absolute paths, str = "C:/foo/my_file.txt".
_________________________________
1 2 3 4 5 6
|
ifstream myfile;
myfile.open (filename_query);
ifstream f("file.txt");
if (myfile.is_open())
cout << f.rdbuf() << endl;
|
You declared two file streams here, my_file and f. Get rid of f, and then change f.rdbuf() to myfile.rdbuf()