cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : Strings library : string : string::push_back
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
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

// 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

string::operator+= Append to string (public member function)
string::append Append to string (public member function)
string::operator= String assignment (public member function)
string::insert Insert into string (public member function)
string::replace Replace part of string (public member function)
string::end Return iterator to end (public member function)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us