c++ - Reading in Lines with 2 numbers each -


i'm pretty rusty on c++. i'm wondering best way read input in following format:

400 200 138 493 ... 

i'm using while(cin.peek()!=-1) check eof, , within that, i'm using while(cin.peek()!='\n') check newlines. fine reading in full lines of text, how can limit 2 numbers and/or grab 2 numbers?

int num1,num2; while(cin>>num1>>num2) {      //... } 

or

string line; int num1,num2; stringstream ss; while(getline(cin,line)) {     ss<<line;     ss>>num1>>num2;     //... } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -