read til the end of line
Moderator: Board moderators
read til the end of line
does anyone know how to read data from file until the end of line in c++?
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
Code: Select all
while(true){
sometype val;
cin >> val;
if(! cin)break;
}
Re: read til the end of line
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;
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
I do something like
But you have to be sure that there is no trailing spaces (usually there arent).
Code: Select all
int a, b;
char c;
scanf("%d%c", &a, &c);
while(c != '\n' && b == 2)
b = scanf("%d%c", &a, &c);