read til the end of line
Posted: Mon Sep 12, 2005 7:25 am
does anyone know how to read data from file until the end of line in c++?
Code: Select all
while(true){
sometype val;
cin >> val;
if(! cin)break;
}
Actually, Krzysztof probably misread your question, his code reads data until the end of file. The most-C++ way of reading data until the end of line is probably the following one:zero_cool wrote:does anyone know how to read data from file until the end of line in c++?
Code: Select all
string S;
getline(cin,S);
stringstream sin(S);
while (sin >> S) cout << "Next token: " << S << endl;
I've seen something like that on this board. There was something with cin.peek ...zero_cool wrote:does anyone know how to read til the end of line without using string???
Code: Select all
int a, b;
char c;
scanf("%d%c", &a, &c);
while(c != '\n' && b == 2)
b = scanf("%d%c", &a, &c);