void resize (size_t n); void resize (size_t n, char c);
测试代码:
// resizing string #include <iostream> #include <string> int main () { std::string str ("I like to code in C"); std::cout << str << ' '; unsigned sz = str.size(); str.resize (sz+2,'+'); std::cout << str << ' '; str.resize (14); std::cout << str << ' '; return 0; }