stringstream doubt

hi, i just learned about stringstream and would like to know why the following code snippet works:

// entry/name/status are vector <string>.
// each element of entry contains "name" then space then status Ex: "ofey departs"

stringstream ss(entry[i]);
ss<<name[i]<<status[i];
//then use name and status as required.

shouldn't the correct thing be:

char c;
stringstream ss(entry[i]);
ss<<name[i]<<c<<status[i];

Note- the first snippet works perfectly.
thanks
I have understood nothing. Can you use a human language?!!!
Presumably you meant:

1
2
std::stringstream ss(entry[i]) ;
ss >> name[i] >> status[i] ;


The extraction operator skips whitespace by default in stringstreams, just like it does anywhere else it is used by streams.
entry is a vector<string> wherein each element is something like "someone departs" or "someone arrives"

a part of some code was:

stringstream ss(entry [i]);
ss<<name[i]<<status[i];

where name and status are vector <strings>.

i don't know much about stringstreams, all i am asking is why does the line in bold work? shouldn't the correct thing be :

ss<<name[i]<<c<<status[i]; (where c is a char)
@cire: thanks. that's what i wanted to know.

and would the other thing work as well, with c being assigned ' ' ?
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <sstream>
#include <iostream>

int main()
{
    char ch ;
    std::string name, status ;
    std::stringstream ss( "someone departs" ) ;

    ss >> name >> ch >> status ;

    std::cout << name << ' ' << ch << ' ' << status << '\n' ;
}
someone d eparts
@Vlad

Your valuable input is highly appreciated.
Thanks.
Last edited on
@ofey

If people restrained themselves from answering questions that weren't clear, concise, and had all of the information needed in it to know exactly what the questioner is asking, the large majority of questions on this forum would never be answered.

This is an international forum. There are quite a few people here for which English is a second (or third) language, please keep that in mind when responding to people. It's far better to assume that there is a communication barrier that needs to be broached rather than to assume that someone is harassing you.

Vlad is a respected member of the community who's been known to help people out. You are someone who's made 4 posts, one of which is littered with profanity. If you don't care for the way he's trying to help you or understand what you're asking, ignore him.

You shall show a little respect for the community by not polluting it with profanity laced, off-topic posts such as this one.

@Vlad - The human language? Really?

You shall show a little respect for the community by not polluting it with profanity laced, off-topic posts such as this one.


A perfectly reasonable demand with which I shall be more than happy to comply.
I was very well aware of the linguistics problem you mention, and thus rephrased my question to a more coherent form.
I was very grateful for your helpful reply and acknowledged the same.

The fact which incensed me was that after I wrote thanks and the problem was resolved, this man, AFTER SEEING THAT THE PROBLEM IS RESOLVED, posts something outrageous, THAT TOO WITHOUT READING THE QUESTION IN FULL. If this isn't harassment, what is?
It was in this outraged state that I wrote the post in question.

Nevertheless, I have nothing but respect for you and shall repeal my post immediately. It was in hope of interacting with people like you, that I joined this beautiful forum, it was my misfortune, alas, that I had this experience with my first question itself.
Last edited on
Topic archived. No new replies allowed.