突然想在一个字符串前面加一个0,在网上查了一些,看着比较麻烦,于是想到了以下办法,简单的记录一下。
#include<iostream>
using namespace std;
#include<sstream>
int main()
{
stringstream ss; //定义一个 stringstream变量,需要包含头文件 include<sstream>
string str="helloWorld";
string res;
ss<<'0'<<str;
ss>>res;
cout<<res<<endl;
}