std::basic_...tream::view(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ¦‹ std::basic_...tream::view(3) πŸ¦‹

okay so bestie, this is from the C++ Standard Libary manual, section 3, and we're talking about std::basic_istringstream::view. It's giving peek-at-the-underlying-string-object energy and I'm lowkey obsessed. πŸ’…


🌸 NAME 🌸

std::basic_istringstream::view - std::basic_istringstream::view β€” yes, that's the name in the source, same name twice, and we are keeping it fr fr. 🫢


✨ Synopsis ✨

std::basic_string_view<CharT, Traits> view() const noexcept;  (since
C++20)

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


πŸŽ€ Parameters πŸŽ€

(none) β€” no parameters, no stress, just call it. 🫢


πŸ¦‹ Return value πŸ¦‹

A std::basic_string_view over the underlying string object. Slay. ✨


πŸ’… Example πŸ’…

Run this code, bestie: πŸ‘‡

// Run this code

#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

πŸ‘‘ See also πŸ‘‘

  • view β€” obtains a view over the underlying character sequence (C++20) (public member function of std::basic_stringbuf<CharT,Traits,Allocator>)

πŸ’– source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::basic_...tream::view(3) πŸ’–

πŸ“¦ where this page comes from