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