
-----------------------------------
SJ
Sat Jun 28, 2008 4:02 pm

How to read until a blank line?
-----------------------------------
Hi I'm working on a spoj problem that requires reading in a series of inputs in cin until a blank line, for example,

1 2 3
4 5 6
10 20 30
*blank line here*

I'm noobishly new to c++ so I'm using cin>> to read in each number, but i don't know when to stop reading in. Is there a "blank line character"? When i program in java i would read in a string, check if it's null, if not then parse it - not sure if that's the way to go in c++. So, can someone give me suggestions?

-----------------------------------
btiffin
Sat Jun 28, 2008 4:56 pm

RE:How to read until a blank line?
-----------------------------------
Hi,

Remove whitespace and newline, and if you have an empty string, you have a blank line.   Or count them and compare to length; same effect, faster.

Or is you are using String, look through the STL or stdlib for a trim type operation or smart empty test.

Cheers

-----------------------------------
OneOffDriveByPoster
Sat Jun 28, 2008 7:21 pm

Re: How to read until a blank line?
-----------------------------------
Random bits of a program that seems to do what you describe:#include 
#include 
#include 

      getline(cin, s);
      istringstream ss(s);

-----------------------------------
SJ
Mon Jun 30, 2008 10:14 am

RE:How to read until a blank line?
-----------------------------------
ahh ty guys, got it working :)
