0

私はコードを書いています

#include<sstream>
#include<iostream>

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

int t =10;
temp>>10;

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

問題があります。一時変数に対してはまったく機能しません。結果として、文字列テストのみで結果が得られ、最後に 10 はありませんか?

}

4

3 に答える 3

2

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

于 2010-11-11T16:29:42.007 に答える
2

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

于 2010-11-11T16:30:00.167 に答える
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.

于 2010-11-11T16:30:07.483 に答える