#include
#include
using namespace std;
int main()
{
string str="value is ";
int a=3;
char ch=(char)(a+int('0'));
str+=ch;
cout< return 0; }
定义如下:
string m;
cin>>m;
cout<
屏幕输入asdassdsa
输出是asdassdsa
但是输入asd sds dsd(有空格)
输出只有asd。
用字符串输出流
头文件: #include
类: ostringstream
#include
#include
int main() {
std::ostringstream out;
out << "The number is " << 3;
std::cout << out.str() << std::endl;
}
#include
#include
using namespace std;
int main() {
stringstream sstr;
int a = 3;
sstr << "value is " << a <<"\n";
cout << sstr.str() << endl;
return 0;
}
char string[100];
int a=3;
sprintf(string,"value is %d",a);
输出string就可以得到
value is 3