std::basic_istringstream<CharT,Traits,Allocator>::str (3) - Linux Manuals
std::basic_istringstream<CharT,Traits,Allocator>::str: std::basic_istringstream<CharT,Traits,Allocator>::str
Command to display std::basic_istringstream<CharT,Traits,Allocator>::str
manual in Linux: $ man 3 std::basic_istringstream<CharT,Traits,Allocator>::str
NAME
std::basic_istringstream<CharT,Traits,Allocator>::str - std::basic_istringstream<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_istringstream<CharT,Traits,Allocator>::str
- std::basic_istringstream<CharT,Traits,Allocator>::basic_istringstream (3) - std::basic_istringstream<CharT,Traits,Allocator>::basic_istringstream
- std::basic_istringstream (3) - std::basic_istringstream
- std::basic_istringstream::operator= (3) - std::basic_istringstream::operator=
- std::basic_istringstream::rdbuf (3) - std::basic_istringstream::rdbuf
- std::basic_istringstream::swap (3) - std::basic_istringstream::swap
- std::basic_istream (3) - std::basic_istream
- std::basic_istream<CharT,Traits>::basic_istream (3) - std::basic_istream<CharT,Traits>::basic_istream
- std::basic_istream<CharT,Traits>::gcount (3) - std::basic_istream<CharT,Traits>::gcount
- std::basic_istream<CharT,Traits>::get (3) - std::basic_istream<CharT,Traits>::get
- std::basic_istream<CharT,Traits>::getline (3) - std::basic_istream<CharT,Traits>::getline
- std::basic_istream<CharT,Traits>::ignore (3) - std::basic_istream<CharT,Traits>::ignore
- std::basic_istream<CharT,Traits>::operator= (3) - std::basic_istream<CharT,Traits>::operator=
- std::basic_istream<CharT,Traits>::operator>> (3) - std::basic_istream<CharT,Traits>::operator>>
- std::basic_istream<CharT,Traits>::peek (3) - std::basic_istream<CharT,Traits>::peek
- std::basic_istream<CharT,Traits>::putback (3) - std::basic_istream<CharT,Traits>::putback
- std::basic_istream<CharT,Traits>::read (3) - std::basic_istream<CharT,Traits>::read
- std::basic_istream<CharT,Traits>::readsome (3) - std::basic_istream<CharT,Traits>::readsome
- std::basic_istream<CharT,Traits>::seekg (3) - std::basic_istream<CharT,Traits>::seekg
- std::basic_istream<CharT,Traits>::sentry (3) - std::basic_istream<CharT,Traits>::sentry