Re: Reading from the command line using stringstreams
From: Blake Kaplan (mrbkap_no_at_spam_rice.edu)
Date: 10/17/03
- Next message: Blake Kaplan: "Re: Reading from the command line using stringstreams"
- Previous message: Anthony Borla: "Re: Inheritance"
- In reply to: mark lawler: "Reading from the command line using stringstreams"
- Next in thread: Blake Kaplan: "Re: Reading from the command line using stringstreams"
- Reply: Blake Kaplan: "Re: Reading from the command line using stringstreams"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 16 Oct 2003 20:31:07 -0500
mark lawler wrote:
> Ok, for my assignment all my classes are working now *hooray* and all
I need
> to do is set up
> the reading from the command line so the user can input commands. Im
using
> getline and a stringstream to achieve this, however I am not really
> achieving much at the moment. Basically it works once, but not the next
> time, as as you can see on the code below, the stream isn't filling up
> again.
>
> CODE:
>
> string line;
> string command;
> string argument;
> string empty;
> stringstream str_stream(line);
Why not move this into the while loop? This way you wouldn't have to
manually set the string each time. Also, why not make this an
istringstream? Do you actually need to stream /into/ it?
>
> While()
> {
> getline(cin, line);
>
> if(line == "")
Stylistic issue: this could be:
if (line.empty())
> {
> continue;
> }
>
> str_stream << line; //here is my problem, all I want to do is put the
> //newly read line into the stream but it doesnąt
> //seem to be doing it. How do I do this?
>
If you don't move the declaration into the while loop, you probably want:
str_stream.str(line);
This sets str_stream's string to point at (a copy of) 'line'.
-- Blake "Before they had drawing boards, what did they go back to?" Remove "_nospam_" from my e-mail address to reply
- Next message: Blake Kaplan: "Re: Reading from the command line using stringstreams"
- Previous message: Anthony Borla: "Re: Inheritance"
- In reply to: mark lawler: "Reading from the command line using stringstreams"
- Next in thread: Blake Kaplan: "Re: Reading from the command line using stringstreams"
- Reply: Blake Kaplan: "Re: Reading from the command line using stringstreams"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|