目录

push_back

描述 (Description)

它将字符c附加到字符串的末尾,将其长度增加1。

声明 (Declaration)

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

void push_back (char c);

C++11

void push_back (char c);

C++14

void push_back (char c);

参数 (Parameters)

c - 这是一个角色对象。

返回值 (Return Value)

没有

异常 (Exceptions)

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

例子 (Example)

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

#include <iostream>
#include <fstream>
#include <string>
int main () {
   std::string str;
   std::ifstream file ("sample.txt",std::ios::in);
   if (file) {
      while (!file.eof()) str.push_back(file.get());
   }
   std::cout << str << '\n';
   return 0;
}
↑回到顶部↑
WIKI教程 @2018