cin.ignore() and cin.getline

Anyone know how to solve my problem? I want make program that can pass the cin name
1
2
3
4
5
char name[50]:{'m','r','/','m','r','s'};
  cout<<"Name:";
  cin.ignore(); //this make so i can pass the cin name
  cin.getline(name,50);
  cout<<"hi,, "<<name;


But i manage to pass the cin name without input, but when i input, that will lost the first char.
This what i got..
Example.
Name: (if i pass this)
Hi,,
...........
Name: Roxane
Hi,, oxane

What i supposed to be:
Name: (pass)
Hi,, mr/mrs
.............
Name: Roxane
Hi,, Roxane
Hello user16,

Simply put comment or remove the "cin.ignore();". You could start with a comment first and see what happens.

What the example output is showing is that the "cin.ignore();" is removing the first character from the input buffer because there is no need for its use in the first place. After the ignore the getline is extracting what is left in the input buffer.

Hope that helps,

Andy
Yeah, thank you for the information, i already solve the problem, thank you
Topic archived. No new replies allowed.