0

我正在编写代码

#include<sstream>
#include<iostream>

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

int t =10;
temp>>10;

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

有一个问题,它对 temp 变量根本不起作用,只是得到结果只有字符串测试,最后没有 10?

}

4

3 回答 3

2

这个问题(对我来说)看起来像一个简单的错字。您需要替换:temp>>10;temp<<10;

于 2010-11-11T16:29:42.007 回答
2

您应该operator<<()改用temp << 10;.

于 2010-11-11T16:30:00.167 回答
0

正如您所包括的那样sstream,我认为您已经考虑到了ostringstream课程。

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

要使用strstream,包括<strstream>. strstream 使用char*,它们是 C 字符串。用于ostringstream处理类型的对象basic_string

于 2010-11-11T16:30:07.483 回答