目录
加星号的是我常用的
string构造函数
string (size_t n, char c);
char c = 'A';
// using string class fill constructor
std::string s(1, c);
std::stringstream *
char c = 'A';
// using stringstream
std::string s;
std::stringstream ss;
ss << c;
ss >> s; // or, use :s = ss.str()`
std::string::push_back
push_back()
char c = 'A';
// using string::push_back
std::string s;
s.push_back(c);
std::string::append
string& append (size_t n, char c);
char c = 'A';
// using `std::string::append`
std::string s;
s.append(1, c);
std::string::assign
tring& assign (size_t n, char c);
char c = 'A';
// using `std::string::assign`
std::string s;
s.assign(1, c);
std::string::operator+= *
string& operator+= (char c);
char c = 'A';
// using `std::string::operator+=`
std::string s;
s += c;
std::string::operator=
string& operator= (char c);
char c = 'A';
// using `std::string::operator=`
std::string s;
s = c;
std::string::insert
string& insert (size_t pos, size_t n, char c);
char c = 'A';
// using `std::string::insert`
std::string s;
s.insert(0, 1, c);
std::string::replace
string& replace (size_t pos, size_t len, size_t n, char c);
char c = 'A';
// using `std::string::replace`
std::string s;
s.replace(0, 1, 1, c);
char -> char* -> string *
std::string
std::string::append
std::string::assign
char c = 'A';
// converting char to C-string
const char* str = &c;
// using `std::string` fill constructor
std::string s(str, 1);
std::cout << s << std::endl;
// using `std::string::append`
std::string S;
S.append(str, 1);
std::cout << S << std::endl;
// using `std::string::assign`
S.assign(str, 1);
std::cout << S << std::endl;