Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
filebuf
fstream
ifstream
ios
iostream
ios_base
istream
istringstream
ofstream
ostream
ostringstream
streambuf
stringbuf
stringstream
objects:
cerr
cin
clog
cout
types:
fpos
streamoff
streampos
streamsize
ostream
ostream::ostream
ostream::~ostream
member classes:
ostream::sentry
member functions:
ostream::flush
ostream::operator<<
ostream::put
ostream::seekp
ostream::tellp
ostream::write


ostream::put

public member function
ostream& put ( char c );

Put character

Writes the character c to the output buffer at the current put position and increases the put pointer to point to the next character.

Parameters

c
Character to write.

Return Value

The function returns *this.

In case of error, the badbit flag is set (which can be checked with member bad). Also, depending on the values set through member exceptions, this may cause an exception of type ios_base::failure to be thrown.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// typewriter
#include <iostream>
#include <fstream>
using namespace std;
int main () {
  char ch;
  ofstream outfile ("test.txt");
  do {
    ch=cin.get();
    outfile.put (ch);
  } while (ch!='.');
  return 0;
}


This example writes to a file everything the user types until a dot (.) is typed.

Basic template member declaration

(basic_ostream<charT,traits>)
1
2
typedef charT char_type;
basic_ostream& put (char_type ch);


See also