cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : ostream : put
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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

// 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>)
typedef charT char_type;
basic_ostream& put (char_type ch);

See also

ostream::write Write block of data (public member function)
ostream::operator<< Insert data with format (public member function)
istream::get Get unformatted data from stream (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us