我正在编写代码
#include<sstream>
#include<iostream>
using namespace std;
int main(){
strstream temp;
int t =10;
temp>>10;
string tt ="testing"+temp.str();
有一个问题,它对 temp 变量根本不起作用,只是得到结果只有字符串测试,最后没有 10?
}
我正在编写代码
#include<sstream>
#include<iostream>
using namespace std;
int main(){
strstream temp;
int t =10;
temp>>10;
string tt ="testing"+temp.str();
有一个问题,它对 temp 变量根本不起作用,只是得到结果只有字符串测试,最后没有 10?
}
这个问题(对我来说)看起来像一个简单的错字。您需要替换:temp>>10;
与temp<<10;
。
您应该operator<<()
改用temp << 10;
.
正如您所包括的那样sstream
,我认为您已经考虑到了ostringstream
课程。
ostringstream temp;
int i = 10;
temp << i;
string tt = "testing" + temp.str();
要使用strstream
,包括<strstream>
. strstream
使用char*
,它们是 C 字符串。用于ostringstream
处理类型的对象basic_string
。