operator<< | function |
ostream& operator<< (ostream& os, string& str); |
<string> |
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. |
Additionaly, 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
// 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
template<class charT, class traits, class Allocator> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& os, basic_string<charT,traits,Allocator>& str ); |
See also
ostream::operator<< | Insert data with format (public member function) |
operator>> | Extract string from istream (function) |