cplusplus.com
C++ : Reference : Strings library : string : push_back
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Strings library
char_traits
classes:
string
global functions:
getline
operator+
operator<<
operator>>
comparison operators
swap
string
string::string
member constants:
string::npos
member functions:
string::append
string::assign
string::at
string::begin
string::capacity
string::clear
string::compare
string::copy
string::c_str
string::data
string::empty
string::end
string::erase
string::find
string::find_first_not_of
string::find_first_of
string::find_last_not_of
string::find_last_of
string::get_allocator
string::insert
string::length
string::max_size
string::operator+=
string::operator=
string::operator[]
string::push_back
string::rbegin
string::rend
string::replace
string::reserve
string::resize
string::rfind
string::size
string::substr
string::swap


string::push_back

public member function
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