C++ 字符串前面加一个0

突然想在一个字符串前面加一个0,在网上查了一些,看着比较麻烦,于是想到了以下办法,简单的记录一下。

#include
using namespace std;
#include

int main()
{
	stringstream ss;		//定义一个 stringstream变量,需要包含头文件 include
	string str="helloWorld";
	string res;
	ss<<'0'<<str;
	ss>>res;
	cout<<res<<endl;
}



C++ 字符串前面加一个0_第1张图片

你可能感兴趣的:(c++)