Okay the idea is to have the user choose 1 of 4 potential slots. The files do exist on the hard drive in the correct directory as 1.txt, 2.txt, 3.txt and 4.txt. All I want to do is let the user select which file to edit, type in a message, and have the program write to that file.
The program compiles and runs fine, but its not doing, what looks to me, like an obvious routine even a laymen (me) couldnt screw up. I understand that i havent included 2-4 in the selection process yet, and thats because all this does is prompt for a choice, displays "Enter a message:" and then abruptly exits. getline() isn't coming up to let me type in the message.
This can't be that hard! What the crap?
Code:
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib> // For EXIT_FAILURE, EXIT_SUCCESS
using namespace std;
int main()
{
string message;
int slot;
//create a name for the file
cout << "Select a slot:" << endl;
cout << "1 | 2 | 3 | 4" << endl;
cin >> slot;
if(slot == 1) {
ofstream SaveFile("1.txt",ios::out|ios::app);
// Get message from user
cout << "Enter a message: " ;
getline(cin,message);
// Write/append message to end of file
SaveFile << message << endl;
}
// else system("pause");
return EXIT_SUCCESS;
}