Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::unique_ptr<T,Deleter>::operator<<

      From cppreference.com
      <cpp‎ |memory‎ |unique ptr
       
       
      Memory management library
      (exposition only*)
      Allocators
      Uninitialized memory algorithms
      Constrained uninitialized memory algorithms
      Memory resources
      Uninitialized storage(until C++20)
      (until C++20*)
      (until C++20*)
      Garbage collector support(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
       
       
      template<class CharT,class Traits,class Y,class D>

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

                                                     conststd::unique_ptr<Y, D>& p);
      (since C++20)

      Inserts the value of the pointer managed byp into the output streamos.

      Equivalent toos<< p.get().

      This overload participates in overload resolution only ifos<< p.get() is a valid expression.

      Contents

      [edit]Parameters

      os - astd::basic_ostream to insertp into
      p - the pointer to be inserted intoos

      [edit]Return value

      os

      [edit]Notes

      Ifstd::unique_ptr<Y, D>::pointer is a pointer to a character type (e.g., whenY ischar([]) orCharT([])), this may end up calling theoverloads ofoperator<< for null-terminated character strings (causing undefined behavior if the pointer does not in fact point to such a string), rather thanthe overload for printing the value of the pointer itself.

      [edit]Example

      Run this code
      #include <iostream>#include <memory> class Foo{}; int main(){auto p=std::make_unique<Foo>();std::cout<< p<<'\n';std::cout<< p.get()<<'\n';}

      Possible output:

      0x6d90280x6d9028

      [edit]See also

      returns a pointer to the managed object
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/unique_ptr/operator_ltlt&oldid=153941"

      [8]ページ先頭

      ©2009-2026 Movatter.jp