comparing int to newline character
Hi, I am trying to figure out how to write a program that will allow the user to enter as many numbers as they want, and store them in a vector<t>. I am using a FOR () loop to accept the input (since I wouldn't know beforehand how many numbers they might want to input). To break out of the loop I am using an if statement that I want to check for the newline character. Of course, the input type is integer, and I recognize that the newline is type character so I am not totally shocked that this isn't working. I just don't know what to do about it. I did verify that if the loop would end, the rest of the code does what I want it to (by using a counting loop). So my question is, what syntax might I use to get the FOR loop to break when the user presses enter?
Thanks!
Here is what I have so far:
Code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout << "Hello.\n";
vector<int> num1;
int bigNum;
cout << "Enter a large number, seperated by spaces such as 987 393 903\n";
for(;;)
{
cin >> bigNum;
if (bigNum == '\n') break; // This is not breaking when "enter" is pressed.
num1.push_back(bigNum);
}
cout << "You entered: ";
for (unsigned i = 0; i < num1.size(); i++)
cout << num1[i] << endl;
}