Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      operator<<(std::basic_string_view)

      From cppreference.com
      <cpp‎ |string‎ |basic string view
       
       
       
      std::basic_string_view
       
      Defined in header<string_view>
      template<class CharT,class Traits>

      std::basic_ostream<CharT, Traits>&
          operator<<(std::basic_ostream<CharT, Traits>& os,

                     std::basic_string_view<CharT, Traits> v);
      (since C++17)

      Behaves as aFormattedOutputFunction. After constructing and checking the sentry object,determines the output format padding.

      Then stores each character from the resulting sequenceseq (the contents ofv with padding) to the output streamos as if by callingos.rdbuf()->sputn(seq, n), wheren isstd::max(os.width(), str.size()).

      Finally, callsos.width(0) to cancel the effects ofstd::setw, if any.

      Contents

      [edit]Exceptions

      May throwstd::ios_base::failure if an exception is thrown during output.

      [edit]Parameters

      os - a character output stream
      v - the view to be inserted

      [edit]Return value

      os

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <string_view> int main(){constexprstd::string_view s{"abc"};constexprint width{5}; // fill/left/right properties are kept until changedstd::cout<<std::setfill('-');std::cout<<std::left; std::cout<<'['<<std::setw(width)<< s<<"]\n";std::cout<<'['<<std::setw(width)<< s<<"]\n"; std::cout<<std::right;std::cout<<'['<<std::setw(width)<< s<<"]\n"; // width is reset after each callstd::cout<<'['<< s<<"]\n";}

      Output:

      [abc--][abc--][--abc][abc]

      [edit]See also

      performs stream input and output on strings
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/basic_string_view/operator_ltlt&oldid=148460"

      [8]ページ先頭

      ©2009-2025 Movatter.jp