来源:https://en.cppreference.com/w/cpp/io/basic_stringstream
继承关系
Member types
Member type | Definition |
---|---|
char_type | CharT |
traits_type | Traits; the program is ill-formed if Traits::char_type is not CharT. |
int_type | Traits::int_type |
pos_type | Traits::pos_type |
off_type | Traits::off_type |
allocator_type | Allocator |
Member functions
- (constructor) constructs the string stream (public member function)
- operator= (C++11) moves the string stream (public member function)
- swap (C++11) swaps two string streams (public member function)
- rdbuf returns the underlying raw string device object (public member function)
String operations
- str gets or sets the contents of underlying string device object (public member function)
- view (C++20) obtains a view over the contents of underlying string device object (public member function)
stringstream 的使用
try {
//pass
} catch (const std::exception& e) {
std::stringstream ss;
ss << e.what();
std::string msg = ss.str();
}
Inherited from std::basic_istream
Member functions
有格式的
- operator>>
extracts formatted data
(public member function of std::basic_istream
无格式的
- get
extracts characters
(public member function of std::basic_istream
) - peek
reads the next character without extracting it
(public member function of std::basic_istream
) - unget
unextracts a character
(public member function of std::basic_istream
) - putback
puts a character into input stream
(public member function of std::basic_istream
) - getline
extracts characters until the given character is found
(public member function of std::basic_istream
) - ignore
extracts and discards characters until the given character is found
(public member function of std::basic_istream
) - read
extracts blocks of characters
(public member function of std::basic_istream
) - readsome
extracts already available blocks of characters
(public member function of std::basic_istream
) - gcount
returns number of characters extracted by last unformatted input operation
(public member function of std::basic_istream
) Positioning - tellg
returns the input position indicator
(public member function of std::basic_istream
) - seekg
sets the input position indicator
(public member function of std::basic_istream
)