public member function

std::string::push_back

<string>
void push_back ( char c );
Append character to string
Appends a single character to the string content, increasing its size by one.

To append more than one character at a time, refer to either member append or operator+= .

Parameters

c
Character to be appended

Return Value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// string::push_back
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main ()
{
  string str;
  ifstream file ("test.txt",ios::in);
  while (!file.eof())
  {
    str.push_back(file.get());
  }
  cout << str;
  return 0;
}


This example reads an entire file character by character, appending each character to a string object using push_back.

Basic template member declarations

( basic_string<charT,traits,Allocator> )
 
void push_back ( charT c );


See also