cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : ostream : put
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
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

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

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