Namespaces
Variants
Actions

std::basic_stringstream<CharT,Traits,Allocator>::view

From cppreference.com
 
C++
 
Input/output library
 
std::basic_stringstream
std::basic_string_view<CharT, Traits> view() const noexcept;
(since C++20)

Obtains a std::basic_string_view over the underlying string object. Equivalent to return rdbuf()->view();.

Contents

[edit] Parameters

(none)

[edit] Return value

A std::basic_string_view over the underlying string object.

[edit] Example

#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';
}

Output:

1) buf1 = [69], n = 69
2) buf2 = [test1]
3) inbuf = [-42], n = -42

[edit] See also

(C++20)
obtains a view over the underlying character sequence
(public member function of std::basic_stringbuf<CharT,Traits,Allocator>) [edit]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant