C++ String 库 - push_back
描述
它将字符 c 附加到字符串的末尾,将其长度增加一。
声明
以下是 std::string::push_back 的声明。
void push_back (char c);
C++11
void push_back (char c);
C++14
void push_back (char c);
参数
c − 它是一个字符对象。
返回值
none
异常
如果抛出异常,则字符串没有变化。
示例
在下面的 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;
}

