std::basic_stringstream<CharT,Traits,Allocator>::str (3) - Linux Manuals
std::basic_stringstream<CharT,Traits,Allocator>::str: std::basic_stringstream<CharT,Traits,Allocator>::str
Command to display std::basic_stringstream<CharT,Traits,Allocator>::str
manual in Linux: $ man 3 std::basic_stringstream<CharT,Traits,Allocator>::str
NAME
std::basic_stringstream<CharT,Traits,Allocator>::str - std::basic_stringstream<CharT,Traits,Allocator>::str
Synopsis
std::basic_string<CharT,Traits,Allocator> str() const; (1)
void str(const std::basic_string<CharT,Traits,Allocator>& new_str); (2)
Manages the contents of the underlying string object.
1) Returns a copy of the underlying string as if by calling rdbuf()->str().
2) Replaces the contents of the underlying string as if by calling rdbuf()->str(new_str).
Parameters
new_str - new contents of the underlying string
Return value
1) a copy of the underlying string object.
2) (none)
Notes
The copy of the underlying string returned by str is a temporary object that will be destructed at the end of the expression, so directly calling c_str() on the result of str() (for example in auto *ptr = out.str().c_str();) results in a dangling pointer.
Example
// Run this code
#include <sstream>
#include <iostream>
int main()
{
int n;
std::istringstream in; // could also use in("1 2")
in.str("1 2");
in >> n;
std::cout << "after reading the first int from \"1 2\", the int is "
<< n << ", str() = \"" << in.str() << "\"\n";
std::ostringstream out("1 2");
out << 3;
std::cout << "after writing the int '3' to output stream \"1 2\""
<< ", str() = \"" << out.str() << "\"\n";
std::ostringstream ate("1 2", std::ios_base::ate);
ate << 3;
std::cout << "after writing the int '3' to append stream \"1 2\""
<< ", str() = \"" << ate.str() << "\"\n";
}
Output:
after reading the first int from "1 2", the int is 1, str() = "1 2"
after writing the int '3' to output stream "1 2", str() = "3 2"
after writing the int '3' to append stream "1 2", str() = "1 23"
See also
replaces or obtains a copy of the associated character string
str (public member function of std::basic_stringbuf<CharT,Traits,Allocator>)
Pages related to std::basic_stringstream<CharT,Traits,Allocator>::str
- std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream (3) - std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream
- std::basic_stringstream (3) - std::basic_stringstream
- std::basic_stringstream::operator= (3) - std::basic_stringstream::operator=
- std::basic_stringstream::rdbuf (3) - std::basic_stringstream::rdbuf
- std::basic_stringstream::swap (3) - std::basic_stringstream::swap
- std::basic_string (3) - std::basic_string
- std::basic_string<CharT,Traits,Allocator>::append (3) - std::basic_string<CharT,Traits,Allocator>::append
- std::basic_string<CharT,Traits,Allocator>::assign (3) - std::basic_string<CharT,Traits,Allocator>::assign
- std::basic_string<CharT,Traits,Allocator>::at (3) - std::basic_string<CharT,Traits,Allocator>::at
- std::basic_string<CharT,Traits,Allocator>::back (3) - std::basic_string<CharT,Traits,Allocator>::back
- std::basic_string<CharT,Traits,Allocator>::basic_string (3) - std::basic_string<CharT,Traits,Allocator>::basic_string
- std::basic_string<CharT,Traits,Allocator>::begin, (3) - std::basic_string<CharT,Traits,Allocator>::begin,
- std::basic_string<CharT,Traits,Allocator>::begin,std::basic_string<CharT,Traits,Allocator>::cbegin (3) - std::basic_string<CharT,Traits,Allocator>::begin,std::basic_string<CharT,Traits,Allocator>::cbegin
- std::basic_string<CharT,Traits,Allocator>::c_str (3) - std::basic_string<CharT,Traits,Allocator>::c_str
- std::basic_string<CharT,Traits,Allocator>::capacity (3) - std::basic_string<CharT,Traits,Allocator>::capacity
- std::basic_string<CharT,Traits,Allocator>::clear (3) - std::basic_string<CharT,Traits,Allocator>::clear
- std::basic_string<CharT,Traits,Allocator>::compare (3) - std::basic_string<CharT,Traits,Allocator>::compare
- std::basic_string<CharT,Traits,Allocator>::copy (3) - std::basic_string<CharT,Traits,Allocator>::copy
- std::basic_string<CharT,Traits,Allocator>::data (3) - std::basic_string<CharT,Traits,Allocator>::data
- std::basic_string<CharT,Traits,Allocator>::empty (3) - std::basic_string<CharT,Traits,Allocator>::empty
- std::basic_string<CharT,Traits,Allocator>::end, (3) - std::basic_string<CharT,Traits,Allocator>::end,