开发者

strstream in c++

I am writing the code

#include<sstream>
#include<iostream>

using namespace std;
int main(){
st开发者_StackOverflowrstream 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?

}


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜