开发者

strstream in c++

开发者 https://www.devze.com 2023-01-24 09:05 出处:网络
I am writing the code #include<sstream> #include<iostream> using namespace std; int main(){ st开发者_StackOverflowrstream temp;

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

精彩评论

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