Re: Reading from the command line using stringstreams

From: Blake Kaplan (mrbkap_no_at_spam_rice.edu)
Date: 10/17/03


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


Relevant Pages

  • Re: Little tutorial about streams
    ... I was debating on whether or not to submit to you a little 'toy' LISP ... Return String is ... For Index in Positive'Succ..List'Last loop ... Atom'Write(Stream, This.Head); ...
    (comp.lang.ada)
  • Re: Designfrage in C#
    ... protected void WriteCommand(string command) ... ... protected string ReadCommand... ... class Command1: CommandBase{ ... eigene Klasse zu packen (am besten als ein von Stream abgeleitete Klasse), ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Problems Updating label Value
    ... while loop because when i comment out the while loop statements...the ... String Email = this.txtEmail.Text; ... //We open a stream for writing the postvars ... //Get the response handle, we have no true ...
    (microsoft.public.dotnet.languages.csharp)
  • TIP #185: Null Handling
    ... nulls, and command modifications for manipulating them. ... Tcl deals with strings, the universal medium for representing data. ... is know and it is an empty string, but if a respondent forgets to give ...
    (comp.lang.tcl)
  • Re: Determine how Word was launched
    ... inspect the command line used to launch Word. ... Private Declare Function GetCommandLineA Lib "kernel32" As Long ... Public Function GetCommandLineAs String ... Dim lngCmdLinePtr As Long ...
    (microsoft.public.office.developer.vba)