0

I am writing the code

#include<sstream>
#include<iostream>

using namespace std;
int main(){
strstream temp;

int t =10;
temp>>10;

string tt ="testing"+temp.str();

Have a problem, it does not work at all for the temp variable, just get in result only string testing without 10 in the end?

}

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
Ptichka
  • 285
  • 3
  • 4
  • 8

3 Answers3

2

The problem looks (to me) like a simple typo. You need to replace: temp>>10; with temp<<10;.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
2

You should use operator<<() instead, temp << 10;.

Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87
0

As you have included sstream, I think you had the ostringstream class in mind.

ostringstream temp;
int i = 10;
temp << i;
string tt = "testing" + temp.str();

To use strstream, include <strstream>. strstream work with char*, which are C strings. Use ostringstream to work with objects of type basic_string.

Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93