public member function
<string>
void push_back (charT c);
Append character to string
Parameters
- c
- Character added to the basic_string.
charT is basic_string's character type (i.e., its first template parameter).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// string::push_back
#include <iostream>
#include <fstream>
#include <string>
int main ()
{
std::string str;
std::ifstream file ("test.txt",std::ios::in);
if (file) {
while (!file.eof()) str.push_back(file.get());
}
std::cout << str << '\n';
return 0;
}
| |
This example reads an entire file character by character, appending each character to a string object using push_back.
Complexity
Unspecified; Generally amortized constant, but up to linear in the new string length.
Iterator validity
Any iterators, pointers and references related to this object may be invalidated.
Data races
The object is modified.