Skip to content

Latest commit

 

History

History
56 lines (39 loc) · 1.18 KB

File metadata and controls

56 lines (39 loc) · 1.18 KB

string字符串类

substr提取部分字符串

string str_new = str.substr(0, length);

c_str()转为char*数组

const char* cstr = str.c_str();

to_string数值转字符串

功能:将数值转化为字符串。返回对应的字符串。

函数原型:

string to_string (int val);
string to_string (long val);
string to_string (long long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (float val);
string to_string (double val);
string to_string (long double val);

char[],char *,string之间转换

char[],char *,string之间转换

string赋值

#include <iostream>
using namespace std;

string num1 = string("111");

string s;
s.push_back(1 + '0');