/* Author: Yan Huang (01.16.07) to show how to get a list of numbers and store them in a list */ #include #include #include using namespace std; int readNumber(int &i){ char c; c = cin.get(); /* updated 02.05, changed < to <= and < to >= */ if ( c<= '9' && c >= '0') cin.unget(); else if (c == '\n') return 0; cin >> i; return 1; } main() { list L; int number; while (readNumber(number)){ L.push_back(number); // Insert a new element at the end } list::iterator i; for(i=L.begin(); i != L.end(); ++i) cout << *i << " "; cout << endl; return 0; }