0%

C++中string和int之间的转换

下述转换属于字符串流,需要附带头文件

1
#include<<sstream>

int 转string

1
2
3
4
5
int number=100;
string str;
stringstream buffer;
buffer<<number;
buffer>>str;</span>

string转int

1
2
3
4
5
int number;
string str="666"
stringstream buffer;
buffer<<str;
buffer>>number;</span>