100 lines
6.7 KiB
HTML
100 lines
6.7 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::filesystem::operator/(std::filesystem::path)</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_filesystem_path_operator_slash 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::filesystem::</span>operator/<span style="font-size:0.7em; line-height:130%">(std::filesystem::path)</span></h1>
|
|
<div id="bodyContent">
|
|
<div id="contentSub"><span class="subpages">< <a href="cpp.html">cpp</a>‎ | <a href="cpp-filesystem.html">filesystem</a>‎ | <a href="cpp-filesystem-path.html">path</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 t-since-cxx17">
|
|
<td>
|
|
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">friend</span> path operator<span class="sy2">/</span><span class="br0">(</span> <span class="kw4">const</span> path<span class="sy3">&</span> lhs, <span class="kw4">const</span> path<span class="sy3">&</span> rhs <span class="br0">)</span><span class="sy4">;</span></span></div>
|
|
</td>
|
|
<td class="t-dcl-nopad"></td>
|
|
<td><span class="t-mark-rev t-since-cxx17">(C++17 起)</span></td>
|
|
</tr>
|
|
<tr class="t-dcl-sep">
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>若适合(细节见 <a href="cpp-filesystem-path-append.html"><tt>operator/=</tt></a> ),则以偏好目录分隔符连接二个路径组分。</p>
|
|
<p>等效于返回 <span class="t-c"><span class="mw-geshi cpp source-cpp">path<span class="br0">(</span>lhs<span class="br0">)</span> <span class="sy2">/</span><span class="sy1">=</span> rhs</span></span> 。</p>
|
|
<p>此函数对通常<a href="cpp-language-unqualified_lookup.html">无限定</a>或<a href="cpp-language-qualified_lookup.html">有限定查找</a>不可见,而只能在 <code>std::filesystem::path</code> 为参数的关联类时由<a href="cpp-language-adl.html">实参依赖查找</a>找到。这阻止存在 <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw1">using</span> <span class="kw1">namespace</span> std<span class="sy4">::</span><span class="me2">filesystem</span><span class="sy4">;</span></span></span> <i>using 指令</i>情况下的不想要的转换。</p>
|
|
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">参数</span></h3>
|
|
<table class="t-par-begin">
|
|
<tr class="t-par">
|
|
<td>lhs, rhs</td>
|
|
<td>-</td>
|
|
<td>要连接的路径</td>
|
|
</tr>
|
|
</table>
|
|
<h3><span class="mw-headline" id=".E8.BF.94.E5.9B.9E.E5.80.BC">返回值</span></h3>
|
|
<p>路径连接的结果。</p>
|
|
<h3><span class="mw-headline" id=".E7.A4.BA.E4.BE.8B">示例</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 <iostream></span>
|
|
<span class="co2">#include <filesystem></span>
|
|
|
|
<span class="kw4">int</span> main<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
|
|
<a href="cpp-filesystem-path.html"><span class="kw2199">std::<span class="me2">filesystem</span><span class="sy4">::</span><span class="me2">path</span></span></a> p <span class="sy1">=</span> <span class="st0">"C:"</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"><<</span> <span class="st0">"<span class="es1">\"</span>C:<span class="es1">\"</span> / <span class="es1">\"</span>Users<span class="es1">\"</span> / <span class="es1">\"</span>batman<span class="es1">\"</span> == "</span>
|
|
<span class="sy1"><<</span> p <span class="sy2">/</span> <span class="st0">"Users"</span> <span class="sy2">/</span> <span class="st0">"batman"</span> <span class="sy1"><<</span> <span class="st0">'<span class="es1">\n</span>'</span><span class="sy4">;</span>
|
|
<span class="br0">}</span></pre></div>
|
|
</div>
|
|
<p>可能的输出:</p>
|
|
<div dir="ltr" class="mw-geshi" style="text-align: left;">
|
|
<div class="text source-text">
|
|
<pre class="de1">"C:" / "Users" / "batman" == "C:Users\batman"</pre></div>
|
|
</div>
|
|
</div>
|
|
<h3><span class="mw-headline" id=".E7.BC.BA.E9.99.B7.E6.8A.A5.E5.91.8A">缺陷报告</span></h3>
|
|
<p>下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。</p>
|
|
<table class="dsctable" style="font-size:0.8em">
|
|
<tr>
|
|
<th>DR</th>
|
|
<th>应用于</th>
|
|
<th>出版时的行为</th>
|
|
<th>正确行为</th>
|
|
</tr>
|
|
<tr>
|
|
<td><a rel="nofollow" class="external text" href="https://cplusplus.github.io/LWG/issue3065">LWG 3065</a></td>
|
|
<td>C++17</td>
|
|
<td>允许存在 <i>using 指令</i>的情况下连接一切可转换成 <code>path</code> 的值</td>
|
|
<td>使之为隐藏友元</td>
|
|
</tr>
|
|
</table>
|
|
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">参阅</span></h3>
|
|
<table class="t-dsc-begin">
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><a href="cpp-filesystem-path-append.html"><span class="t-lines"><span>append</span><span>operator/=</span></span></a></div>
|
|
</div>
|
|
</td>
|
|
<td>添加元素到带目录分隔符的路径<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="visualClear"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|