Cin C + +. getline reads one character

I’m using Xcode 4.5 and I have the following code in my program:

string str;
char strChar[5];
cin.getline(strChar, 5);
int i = atoi(str.basic_string::c_str());

When I start to try and enter a number, after the first number is pressed, the console will not accept any more input (other than the enter key, in which case the program just returns zero straight away). Obviously, I want to accept more than one character, how can I accomplish this?

Thanks for answering my question

This entry was posted in Codes & Scripts and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>