<string>
ostream& operator<< (ostream& os, const string& str);
Insert string into stream
Inserts the string object str into the output stream os.
This function overloads the global operator<< to behave as described in ostream::operator<< but applied to string objects.
Parameters
- os
- ostream object on which the insertion operation is performed.
- str
- string object output by the operation.
Return Value
The same as parameter os.
Errors are signaled by modifying the internal state flags:
flag | error |
eofbit | - |
failbit | When used with a streambuf object as parameter, failbit is set on if no characters could be extracted from it. |
badbit | An error other than the above happened. |
(see ios_base::iostate for more info on these)
Additionally, in any of these cases, if the appropriate flag has been set with member function ios::exceptions, an exception of type ios_base::failure is thrown.
If some error happens during the output operation, the stream's badbit flag is set, and if the appropriate flag has been set with ios::exceptions, an exception is thrown.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// example on insertion
#include <iostream>
#include <string>
using namespace std;
int main () {
int n;
string str ("test string");
cout << str << endl;
return 0;
}
|
Basic template declaration
1 2 3 4
|
template<class charT, class traits, class Allocator>
basic_ostream<charT,traits>&
operator<<(basic_ostream<charT,traits>& os,
const basic_string<charT,traits,Allocator>& str );
|
See also
|