help with storing input as vector!

i have the following code but it doesn't seem to be working. anyone could tell me what's wrong with the loop and how I should do it? thank you!


int i=0;


// storing the first inputted number as vector of characters named number_1


vector<char> number_1;

char number1;

cout << "Enter a non-negative number: \n";

do

{

cin.get(number1);

number_1.push_back(number1);

}

while (number1);


// storing the second inputted number as vector of characters named number_2


vector<char> number_2;

char number2;


cout << "Enter a non-negative number: \n";

do

{

cin.get(number2);

number_2.push_back(number2);

}

while (number2);

i have the following code but it doesn't seem to be working.


What do you mean by "not working"?
What do you mean by "not working"?


Was my first question!

And please use code tags!
When I run the program, the first line of output "Enter a non-negative integer: " shows, and then after an input is typed and enter's pressed the rest of the program doesn't run.
Because it still wants you to type stuff in. Your loop conditions run until the null character is entered, not until the newline character is entered.
You've sort of got an infinite loop there.

You ask for a number then enter the loop. In this loop, you're expecting the user to input something and then push it to the vector. Then it goes back to the start of the loop, expecting another input from the user.

EDIT: It's not really infinite. If you entered 0 for the input, it'd kick out. However, it's not even prompting the user with any output.
Last edited on
It's not infinite if you enter the null character ;) if you even can ;p
Yup, realised that wasn't the best way of describing it. Got a quick edit in but you called me on it. :-P
ooh, thank you! what code do I use to get out of the loop when the user inputs enter?
while(number1 != '\n')
oh it's working now, thank you!!!
Topic archived. No new replies allowed.