function
<string>

std::operator<< (string)

ostream& operator<< (ostream& os, const string& str);
Insert string into stream
Inserts the sequence of characters that conforms value of str into os.

This function overloads operator<< to behave as described in ostream::operator<< for c-strings, but applied to string objects.

Parameters

os
ostream object where characters are inserted.
str
string object with the content to insert.

Return Value

The same as parameter os.

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
// inserting strings into output streams
#include <iostream>
#include <string>

main ()
{
  std::string str = "Hello world!";
  std::cout << str << '\n';
  return 0;
}

Complexity

Unspecified, but generally linear in str's length.

Iterator validity

No changes.

Data races

Objects os is modified.

Exception safety

Basic guarantee: if an exception is thrown, both is and str end up in a valid state.

See also