std::basic_stringstream<CharT,Traits,Allocator>::view
來自 cppreference.com
< cpp | io | basic stringstream
std::basic_string_view<CharT, Traits> view() const noexcept; |
(C++20 起) | |
獲取底層字串物件的 std::basic_string_view。等價於 return rdbuf()->view();。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
底層字串物件的 std::basic_string_view。
[編輯] 示例
執行此程式碼
#include <iostream> #include <sstream> int main() { // input/output stream std::stringstream buf1; buf1 << 69; int n = 0; buf1 >> n; std::cout << "1) buf1 = [" << buf1.view() << "], n = " << n << '\n'; // output stream in append mode std::ostringstream buf2("test", std::ios_base::ate); buf2 << '1'; std::cout << "2) buf2 = [" << buf2.view() << "]\n"; // input stream std::istringstream inbuf("-42"); inbuf >> n; std::cout << "3) inbuf = [" << inbuf.view() << "], n = " << n << '\n'; }
輸出
1) buf1 = [69], n = 69 2) buf2 = [test1] 3) inbuf = [-42], n = -42
[編輯] 參閱
(C++20) |
獲取底層字元序列的檢視 ( std::basic_stringbuf<CharT,Traits,Allocator> 的公開成員函式) |