开发者

getline() omitting the first letter of my output string

Hi i am a newbie in c++ and was doing some basic exercise. my code takes user input and feeds them in an array. Now i am using getline() to get the input string. my code is as follows:

cin.getline(cb[0].name, 200).get();        // Cadburry
cin.getline(cb[1].name, 200).get();        // Snickers
cin.getline(cb[2开发者_运维问答].name, 200);              // Milky Bar

But when i output the strings, the first getline() seems to be fine but the other two are omitting the first letter of the string. So the output in this case is :

Cadburry
nickers
ilky Bar 

can anyone please tell me why is it so?


The get() calls are consuming the S and the M, remove those and it will work. getline() already consumes the \n

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜