目录

(constructor)

描述 (Description)

它用于构造字符串对象。并根据所使用的构造函数版本初始化其值。

声明 (Declaration)

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

string();

参数 (Parameters)

  • str - 它是另一个字符串对象。

  • pos - 它包含第一个字符串的位置。

  • len - 它包含子字符串的长度。

  • s - 指向字符数组的指针。

  • n - 它包含有关要复制的字符数的信息。

  • c - 填充字符串的字符。

  • first, last - 它是一个输入迭代器,用于查找范围内的初始和最终位置。

  • il - 它是一个initializer_list对象。

返回值 (Return Value)

没有

异常 (Exceptions)

永远不要抛出任何异常。

例子 (Example)

在下面的示例中为std :: string :: string。

#include <iostream>
#include <string>
int main () {
   std::string s0 ("initial string");
   std::string s1;
   std::string s2 (s0);
   std::string s3 (s0, 8, 3);
   std::string s4 ("A character sequence", 6);
   std::string s5 ("Another character sequence");
   std::string s6a (10, 'x');
   std::string s6b (10, 42);
   std::string s7 (s0.begin(), s0.begin()+7);
   std::cout << "s1: " << s1 << "\ns2: " << s2 << "\ns3: " << s3;
   std::cout << "\ns4: " << s4 << "\ns5: " << s5 << "\ns6a: " << s6a;
   std::cout << "\ns6b: " << s6b << "\ns7: " << s7 << '\n';
   return 0;
}

样本输出应该是这样的 -

s1:
s2: initial string
s3: str
s4: A char
s5: Another character sequence
s6a: xxxxxxxxxx
s6b: **********
s7: initial
↑回到顶部↑
WIKI教程 @2018