Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to read until a blank line?
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SJ




PostPosted: Sat Jun 28, 2008 4:02 pm   Post subject: 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?
Sponsor
Sponsor
Sponsor
sponsor
btiffin




PostPosted: Sat Jun 28, 2008 4:56 pm   Post subject: 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




PostPosted: Sat Jun 28, 2008 7:21 pm   Post subject: Re: How to read until a blank line?

Random bits of a program that seems to do what you describe:
c++:
#include <iostream>
#include <sstream>
#include <string>

      getline(cin, s);
      istringstream ss(s);
SJ




PostPosted: Mon Jun 30, 2008 10:14 am   Post subject: RE:How to read until a blank line?

ahh ty guys, got it working Smile
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: