getline and cin confusion

hi. confused with following two questions?
1. can't we use getline for char type?

2. i am confused in this part of the code.

1
2
3
4
5
6
7
char separator;
    string input;
cout<<"Enter the character for separator: ";
    cin>>separator;
    cout<<"Enter stuffs with separator character: ";
    getline(cin,input,'\n');  


running this program, when i enter vale for separator(like ',' or'@'), i am not prompted to enter input for the second part. but if i switch the places of respective cout statements(second cout and cin at first) i am prompted to enter input for both cout statement. any ideas why does this happen?

closed account (SECMoG1T)
cin>>separator; this operation reads only one character from the standard input stream , if your keyed in a char and then pressed the return button to proceed to the next line the new line character is left in the stream and will be read by you getline instruction, a solution would be to clear your stream of any leftover characters using cin.ignore() function
it worked! thanks
Topic archived. No new replies allowed.