类型转换
ostringstream.str(); // 转换为string类型
string.c_str(); // 转换为const char*类型
#include <sstream>
#include <string>
int main(int, char**)
{
std::ostringstream oss;
oss << "hello world";
string str = oss.str();
const char* c = str.c_str();
return 0;
}
string
- replace
std::string name("insideZhang");
name.replace(0, 1, "I");
// first, last: 表示区间
// 第三个参数虽然只有一个字符,仍然要加双引号