目录

resize

描述 (Description)

它将字符串的大小调整为n个字符的长度。

声明 (Declaration)

以下是std :: string :: resize的声明。

void resize (size_t n);

C++11

void resize (size_t n, char c);

参数 (Parameters)

  • n - 这是一个新的字符串长度。

  • c - 用于填充添加到字符串的新字符空间的字符。

返回值 (Return Value)

没有

异常 (Exceptions)

如果抛出异常,则字符串中没有变化。

例子 (Example)

在下面的示例中,std :: string :: resize。

#include <iostream>
#include <string>
int main () {
   std::string str ("Sairamkrishna Mammahe");
   std::cout << str << '\n';
   unsigned sz = str.size();
   str.resize (sz+2,'+');
   std::cout << str << '\n';
   str.resize (14);
   std::cout << str << '\n';
   return 0;
}

样本输出应该是这样的 -

Sairamkrishna Mammahe
Sairamkrishna Mammahe++
Sairamkrishna 
↑回到顶部↑
WIKI教程 @2018