headbanger
headbanger

Reputation: 1102

How can I add a char to an istringstream?

I'm trying to add a char to an istringstream - as so:

using namespace std;
istringstream input_buffer;    
char c;

while (is.get(c)) {
    input_buffer << c;
}

Sadly, this results in:

 error: invalid operands to binary expression ('std::__1::istringstream' (aka 'basic_istringstream<char>') and 'int')

What am I doing wrong? How can I do it right?

Upvotes: 0

Views: 550

Answers (1)

R Sahu
R Sahu

Reputation: 206567

I'm trying to add a char to an istringstream

You cannot do that. It does not make sense either.

You are expected to read from an istringstream and write to an ostringstream.

Use ostringstream instead.

ostringstream output_buffer;    

while (is.get(c)) {
    output_buffer << c;
}

Upvotes: 5

Related Questions