Files
hustoj/web/cppreference-zh/chmhelp/cpp-memory-shared_ptr-operator_ltlt.html
2025-08-01 12:57:54 +08:00

93 lines
5.4 KiB
HTML

<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh">
<head><meta http-equiv="x-ua-compatible" content="ie=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>std::shared_ptr&lt;T&gt;::operator&lt;&lt;</title>
<link rel="stylesheet" href="ext.css" />
<link rel="stylesheet" href="site_modules.css" />
</head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_memory_shared_ptr_operator_ltlt skin-cppreference2 action-view cpp-navbar">
<div id="cpp-content-base">
<div id="content"><a id="top"></a>
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">std::shared_ptr&lt;T&gt;::</span>operator&lt;&lt;</h1>
<div id="bodyContent">
<div id="contentSub"><span class="subpages">&lt; <a href="cpp.html">cpp</a>&lrm; | <a href="cpp-memory.html">memory</a>&lrm; | <a href="cpp-memory-shared_ptr.html">shared ptr</a></span></div>
<div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr" xml:lang="zh">
<table class="t-dcl-begin">
<tbody>
<tr class="t-dcl">
<td class="t-dcl-nopad">
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">template</span> <span class="sy1">&lt;</span><span class="kw1">class</span> T, <span class="kw1">class</span> U, <span class="kw1">class</span> V<span class="sy1">&gt;</span><br />
&nbsp; &nbsp; <a href="cpp-io-basic_ostream.html"><span class="kw1715">std::<span class="me2">basic_ostream</span></span></a><span class="sy1">&lt;</span>U, V<span class="sy1">&gt;</span><span class="sy3">&amp;</span> operator<span class="sy1">&lt;&lt;</span><span class="br0">(</span><a href="cpp-io-basic_ostream.html"><span class="kw1715">std::<span class="me2">basic_ostream</span></span></a><span class="sy1">&lt;</span>U, V<span class="sy1">&gt;</span><span class="sy3">&amp;</span> os, <span class="kw4">const</span> <a href="cpp-memory-shared_ptr.html"><span class="kw734">std::<span class="me2">shared_ptr</span></span></a><span class="sy1">&lt;</span>T<span class="sy1">&gt;</span><span class="sy3">&amp;</span> ptr<span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td class="t-dcl-nopad"></td>
<td class="t-dcl-nopad"></td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>&#25554;&#20837;&#23384;&#20648;&#20110; <span class="t-spar">ptr</span> &#30340;&#25351;&#38024;&#20540;&#21040;&#36755;&#20986;&#27969; <span class="t-spar">os</span> &#20013;&#12290;</p>
<p>&#31561;&#20215;&#20110; <code>os &lt;&lt; ptr.get()</code> &#12290;</p>
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">&#21442;&#25968;</span></h3>
<table class="t-par-begin">
<tr class="t-par">
<td>os</td>
<td>-</td>
<td>&#35201;&#25554;&#20837; <code>ptr</code> &#21040;&#30340; <span class="t-lc"><a href="cpp-io-basic_ostream.html">std::basic_ostream</a></span></td>
</tr>
<tr class="t-par">
<td>ptr</td>
<td>-</td>
<td>&#34987;&#25554;&#20837;&#21040; <code>os</code> &#30340;&#25968;&#25454;</td>
</tr>
</table>
<h3><span class="mw-headline" id=".E8.BF.94.E5.9B.9E.E5.80.BC">&#36820;&#22238;&#20540;</span></h3>
<p><code>os</code></p>
<h3><span class="mw-headline" id=".E7.A4.BA.E4.BE.8B">&#31034;&#20363;</span></h3>
<div class="t-example">
<div class="t-example-live-link"></div>
<div dir="ltr" class="mw-geshi" style="text-align: left;">
<div class="cpp source-cpp">
<pre class="de1"><span class="co2">#include &lt;iostream&gt;</span>
<span class="co2">#include &lt;memory&gt;</span>
<span class="kw1">class</span> Foo <span class="br0">{</span><span class="br0">}</span><span class="sy4">;</span>
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
<span class="kw4">auto</span> sp <span class="sy1">=</span> <a href="cpp-memory-shared_ptr-make_shared.html"><span class="kw736">std::<span class="me2">make_shared</span></span></a><span class="sy1">&lt;</span>Foo<span class="sy1">&gt;</span><span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span>
<a href="cpp-io-cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> sp <span class="sy1">&lt;&lt;</span> <a href="cpp-io-manip-endl.html"><span class="kw1791">std::<span class="me2">endl</span></span></a><span class="sy4">;</span>
<a href="cpp-io-cout.html"><span class="kw1758">std::<span class="me2">cout</span></span></a> <span class="sy1">&lt;&lt;</span> sp.<span class="me1">get</span><span class="br0">(</span><span class="br0">)</span> <span class="sy1">&lt;&lt;</span> <a href="cpp-io-manip-endl.html"><span class="kw1791">std::<span class="me2">endl</span></span></a><span class="sy4">;</span>
<span class="br0">}</span></pre></div>
</div>
<p>&#21487;&#33021;&#30340;&#36755;&#20986;&#65306;</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;">
<div class="text source-text">
<pre class="de1">0x6d9028
0x6d9028</pre></div>
</div>
</div>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">&#21442;&#38405;</span></h3>
<table class="t-dsc-begin">
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-memory-shared_ptr-get.html"><span class="t-lines"><span>get</span></span></a></div>
</div>
</td>
<td>&#36820;&#22238;&#23384;&#20648;&#30340;&#25351;&#38024;<br />
<span class="t-mark">(&#20844;&#24320;&#25104;&#21592;&#20989;&#25968;)</span></td>
</tr>
</table>
</div>
<div class="visualClear"></div>
</div>
</div>
</div>
</body>
</html>