End of Line in C/C++

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
Verdan
New poster
Posts: 5
Joined: Wed Sep 17, 2003 10:56 am

End of Line in C/C++

Post by Verdan »

Hello!
Can you tell me, how can I check if there is EOLN (End Of LiNe (like in Pascal)) while reading from input.


Something like:
[pascal]
While Not EOLN(input) do
read(i);
[/pascal]
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

For instance, you can save the line in a string and then parse it. All you need is to include <string> and <iostream> and then write
[cpp]string line;
getline(cin,line);[/cpp]
If you want to parse with a stringstream, add
[cpp]#include <sstream>[/cpp]
Miguel Angel
Learning poster
Posts: 60
Joined: Tue Aug 13, 2002 2:39 am
Location: Mexico

An easy way

Post by Miguel Angel »

[cpp]
while (cin.peek()!='\n')
[/cpp]
:D Miguel & Marina :D
Verdan
New poster
Posts: 5
Joined: Wed Sep 17, 2003 10:56 am

Post by Verdan »

Thank you very much!
Post Reply

Return to “C++”