String.resize()

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;
}

  

原文地址:https://www.cnblogs.com/icode-girl/p/5365004.html