Why would the addition of an 'if' statement makes the program skip the getline

This program works fine if I don't use a if/else or switch. I am sure it has to do with the getline() function. When I switch to cin>> it works with the if/else; but I need the getline() because I want to include white space.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main () {
char menu;
cin>>menu;
if(menu=='a'){
string message;
ofstream code;
char coder;
cout << "Please enter full name: ";
getline (cin,message);
code.open("code.txt");
for (size_t i=0; i < message.length(); i++){
coder=message.at(i);
code<<(int)coder;
code<<" ";
}
code.close();
}

return 0;
}
You really should learn to use indentation. It makes it much easier to read the code.

Have you read my answer I wrote earlier today? http://cplusplus.com/forum/beginner/60177/#CH_i325008
Topic archived. No new replies allowed.