Important
此页面记录了标头提供的<experimental/filesystem>已删除Microsoft标准std::experimental::filesystem::path实现。 它 不是 C++17 std::filesystem::path 类。 此标准实现基于 文件系统技术规范 (N4100)和 Predates C++17 std::filesystem。 从 <experimental/filesystem> Microsoft Visual C++ 工具集 14.51 开始删除标头和std::experimental::filesystem命名空间。 有关当前支持的 C++17 实现,请参阅 path 类。
该 path 类存储一个类型 string_type的对象,此处调用 myname 用于解释,适合用作路径名。
string_type是Windows的同义词basic_string<value_type>value_type。wchar_t
语法
class path;
构造函数
| 构造函数 | 说明 |
|---|---|
path |
构造一个 path。 |
Typedef
| 类型名称 | 说明 |
|---|---|
const_iterator |
iterator 的同义词。 |
iterator |
一个双向常量迭代器,用于指定 path . 的 myname组件。 |
string_type |
类型是 basic_string<value_type> 的同义词。 |
成员函数
| 成员函数 | 说明 |
|---|---|
append |
根据需要将指定的序列追加到 myname、转换和插入preferred_separator。 |
assign |
替换为 myname 指定序列,根据需要转换。 |
begin |
返回指定 pathname 中的第一个 path::iterator path 元素(如果存在)。 |
c_str |
返回指向第一个字符的 myname指针。 |
clear |
执行myname.clear()。 |
compare |
返回比较值。 |
concat |
根据需要将指定的序列追加到 myname转换后(但不插入分隔符)。 |
empty |
返回 myname.empty()。 |
end |
返回类型的 iterator序列结束迭代器。 |
extension |
返回 . 的 filename()后缀。 |
filename |
返回文件名组件 myname,具体 empty() ? path() : *--end()来说。 该组件可能为空。 |
generic_string |
返回this->string<Elem, Traits, Alloc>(al)与 (在 Windows) 下的任何反斜杠转换为正斜杠。 |
generic_u16string |
返回u16string()与 (在 Windows) 下的任何反斜杠转换为正斜杠。 |
generic_u32string |
在历史 MSVC 实现中删除。 |
generic_u8string |
返回u8string()与 (在 Windows) 下的任何反斜杠转换为正斜杠。 |
generic_wstring |
返回wstring()与 (在 Windows) 下的任何反斜杠转换为正斜杠。 |
has_extension |
返回 !extension().empty()。 |
has_filename |
返回 !filename().empty()。 |
has_parent_path |
返回 !parent_path().empty()。 |
has_relative_path |
返回 !relative_path().empty()。 |
has_root_directory |
返回 !root_directory().empty()。 |
has_root_name |
返回 !root_name().empty()。 |
has_root_path |
返回 !root_path().empty()。 |
has_stem |
返回 !stem().empty()。 |
is_absolute |
对于Windows,该函数返回 has_root_name() && has_root_directory()。 对于 POSIX,该函数返回 has_root_directory()。 |
is_relative |
返回 !is_absolute()。 |
make_preferred |
根据需要将每个分隔符转换为一个 preferred_separator 。 |
native |
返回路径的本机表示形式。 |
parent_path |
返回 . 的 myname父路径组件。 |
preferred_separator |
常量对象提供用于分隔路径组件的首选字符,具体取决于主机操作系统。 |
relative_path |
返回 . 的 myname相对路径组件。 |
remove_filename |
删除文件名。 |
replace_extension |
替换 . 的 myname扩展名。 |
replace_filename |
替换文件名。 |
root_directory |
返回 . 的 myname根目录组件。 |
root_name |
返回 . 的 myname根名称组件。 |
root_path |
返回 . 的 myname根路径组件。 |
stem |
返回 stem . 的 myname组件。 |
string |
转换存储在 . 中的 myname序列。 |
swap |
执行swap(myname, right.myname)。 |
u16string |
将存储到 myname UTF-16 中的序列,并返回存储在类型对象 u16string中的序列。 |
u32string |
在历史 MSVC 实现中删除。 |
u8string |
将存储在 UTF-8 中的 myname 序列转换为 UTF-8,并返回存储在类型的 u8string对象中。 |
value_type |
该类型描述主机操作系统青睐的路径元素。 |
wstring |
将存储在 myname 主机系统的 wchar_t 编码中存储的序列转换为序列所青睐的编码,并返回存储在类型对象 wstring中的序列。 |
Operators
| Operator | 说明 |
|---|---|
operator= |
将路径的元素替换为另一个路径的副本。 |
operator+= |
各种 concat 表达式。 |
operator/= |
各种 append 表达式。 |
operator string_type |
返回 myname。 |
要求
标头:<experimental/filesystem>
命名 空间:std::experimental::filesystem
path::append
将指定的序列追加到 myname、转换并根据需要插入 preferred_separator 。
template <class Source>
path& append(const Source& source);
template <class InIt>
path& append(InIt first, InIt last);
Parameters
source
指定的序列。
first
指定序列的开始。
last
指定序列的末尾。
path::assign
替换为 myname 指定序列,根据需要转换。
template <class Source>
path& assign(const Source& source);
template <class InIt>
path& assign(InIt first, InIt last);
Parameters
source
指定的序列。
first
指定序列的开始。
last
指定序列的末尾。
path::begin
返回指定 pathname 中的第一个 path::iterator path 元素(如果存在)。
iterator begin() const;
path::c_str
返回指向第一个字符的 myname指针。
const value_type* c_str() const noexcept;
path::clear
执行myname.clear()。
void clear() noexcept;
path::compare
第一个函数返回 myname.compare(pval.native())。 第二个函数返回 myname.compare(str)。 第三个函数返回 myname.compare(ptr)。
int compare(const path& pval) const noexcept;
int compare(const string_type& str) const;
int compare(const value_type *ptr) const;
Parameters
pval
要比较的路径。
str
要比较的字符串。
ptr
要比较的指针。
path::concat
根据需要将指定的序列追加到 myname转换后(但不插入分隔符)。
template <class Source>
path& concat(const Source& source);
template <class InIt>
path& concat(InIt first, InIt last);
Parameters
source
指定的序列。
first
指定序列的开始。
last
指定序列的末尾。
path::const_iterator
iterator 的同义词。
typedef iterator const_iterator;
path::empty
返回 myname.empty()。
bool empty() const noexcept;
path::end
返回类型的 iterator序列结束迭代器。
iterator end() const;
path::extension
返回 . 的 filename()后缀。
path extension() const;
备注
返回以下项的 filename() X 后缀:
如果 X == path(".") || X == path("..") 或如果 X 不包含点,则后缀为空。
否则,后缀以最右侧的点开头(包括)。
path::filename
返回文件名组件 myname,具体 empty() ? path() : *--end()来说。 该组件可能为空。
path filename() const;
path::generic_string
返回this->string<Elem, Traits, Alloc>(al)与 (在 Windows) 下的任何反斜杠转换为正斜杠。
template <class Elem,
class Traits = char_traits<Elem>,
class Alloc = allocator<Elem>>
basic_string<Elem, Traits, Alloc>
generic_string(const Alloc& al = Alloc()) const;
string generic_string() const;
path::generic_u16string
返回u16string()与 (在 Windows) 下的任何反斜杠转换为正斜杠。
u16string generic_u16string() const;
path::generic_u32string
此函数在历史 MSVC 实现中被删除。
u32string generic_u32string() const = delete;
path::generic_u8string
返回u8string()与 (在 Windows) 下的任何反斜杠转换为正斜杠。
string generic_u8string() const;
path::generic_wstring
返回wstring()与 (在 Windows) 下的任何反斜杠转换为正斜杠。
wstring generic_wstring() const;
path::has_extension
返回 !extension().empty()。
bool has_extension() const;
path::has_filename
返回 !filename().empty()。
bool has_filename() const;
path::has_parent_path
返回 !parent_path().empty()。
bool has_parent_path() const;
path::has_relative_path
返回 !relative_path().empty()。
bool has_relative_path() const;
path::has_root_directory
返回 !root_directory().empty()。
bool has_root_directory() const;
path::has_root_name
返回 !root_name().empty()。
bool has_root_name() const;
path::has_root_path
返回 !root_path().empty()。
bool has_root_path() const;
path::has_stem
返回 !stem().empty()。
bool has_stem() const;
path::is_absolute
对于Windows,该函数返回 has_root_name() && has_root_directory()。 对于 POSIX,该函数返回 has_root_directory()。
bool is_absolute() const;
path::is_relative
返回 !is_absolute()。
bool is_relative() const;
path::iterator
一个双向常量迭代器,用于指定 . 的路径组件 myname。
class iterator
{
// bidirectional iterator for path
typedef bidirectional_iterator_tag iterator_category;
typedef path_type value_type;
typedef ptrdiff_t difference_type;
typedef const value_type *pointer;
typedef const value_type& reference;
// ...
};
备注
该类描述一个双向常量迭代器,该迭代器指定 path 序列中的组件 myname :
根名称(如果存在)
根目录(如果存在)
父
path级的剩余目录元素(如果存在)以文件名结尾(如果存在)
对于pval类型为 :path
path::iterator X = pval.begin()指定 pathname 中的第一个path元素(如果存在)。X == pval.end()当trueX点刚过组件序列的末尾时。*X返回与当前组件匹配的字符串++X指定序列中的下一个组件(如果存在)。--X指定序列中的上述组件(如果存在)。myname更改会使指定元素的所有myname迭代器失效。
path::make_preferred
根据需要将每个分隔符转换为一个 preferred_separator 。
path& make_preferred();
path::native
获取路径的本机字符串表示形式。
const string_type& native() const noexcept;
备注
该路径以可移植泛型格式(见 generic_string())或路径的本机格式提供。 此函数返回本机字符串。 在 POSIX 系统上,通用格式和本机格式相同。
在Windows上运行的以下示例中,泛型路径字符串是c:/t/temp.txt本机字符串c:\t\temp.txt。
// Compile with /std:c++14 and _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING defined.
#include <experimental/filesystem>
int main()
{
std::experimental::filesystem::path p(LR"(c:\t\temp.txt)");
auto native = p.native(); // Windows: L"c:\\t\\temp.txt"
auto generic = p.generic_string(); // Windows: "c:/t/temp.txt"
}
path::operator=
将路径的元素替换为另一个路径的副本。
path& operator=(const path& right);
path& operator=(path&& right) noexcept;
template <class Source>
path& operator=(const Source& source);
Parameters
right
要 path 复制到的 path。
source
源 path。
备注
第一个成员运算符复制到 right.mynamemyname。 第二个成员运算符移动到 right.mynamemyname。 第三个成员运算符的行为与 *this = path(source).
path::operator+=
各种 concat 表达式。
path& operator+=(const path& right);
path& operator+=(const string_type& str);
path& operator+=(const value_type *ptr);
path& operator+=(value_type elem);
template <class Source>
path& operator+=(const Source& source);
template <class Elem>
path& operator+=(Elem elem);
Parameters
right
添加的路径。
str
添加的字符串。
ptr
添加的指针。
elem
已添加 value_type 或 Elem。
source
添加的源。
备注
成员函数的行为与以下相应的表达式相同:
concat(right);concat(path(str));concat(ptr);concat(string_type(1, elem));concat(source);concat(path(basic_string<Elem>(1, elem)));
path::operator/=
各种 append 表达式。
path& operator/=(const path& right);
template <class Source>
path& operator/=(const Source& source);
Parameters
right
添加的路径。
source
添加的源。
备注
成员函数的行为与以下相应的表达式相同:
append(right);append(source);
path::operator string_type
返回 myname。
operator string_type() const;
path::parent_path
返回 . 的 myname父路径组件。
path parent_path() const;
备注
返回 的父路径组件 myname,特别是 myname 删除 filename().native() 后前缀以及紧邻目录分隔符的任何前缀。 (同样,如果是begin() != end(),则通过连续应用operator/=来合并区域中[begin(), --end())的所有元素。该组件可能为空。
path::path
path以各种方式构造。
path();
path(const path& right);
path(path&& right) noexcept;
template <class Source>
path(const Source& source);
template <class Source>
path(const Source& source, const locale& loc);
template <class InIt>
path(InIt first, InIt last);
template <class InIt>
path(InIt first, InIt last, const locale& loc);
Parameters
right
构造路径要作为副本的路径。
source
构造路径要作为副本的源。
loc
指定的区域设置。
first
要复制的第一个元素的位置。
last
要复制的最后一个元素的位置。
备注
构造函数以各种方式构造 myname :
就这样path()myname()。
是 path(const path& right的 myname(right.myname)。
就这样path(path&& right)myname(right.myname)。
就这样template<class Source> path(const Source& source)myname(source)。
myname(source)因此template<class Source> path(const Source& source, const locale& loc),从loc中获取所需的codecvt任何方面。
就这样template<class InIt> path(InIt first, InIt last)myname(first, last)。
myname(first, last)因此template<class InIt> path(InIt first, InIt last, const locale& loc),从loc中获取所需的codecvt任何方面。
path::preferred_separator
常量对象提供用于分隔路径组件的首选字符,具体取决于主机操作系统。
#if _WIN32_C_LIB
static constexpr value_type preferred_separator = L'\\';
#else // assume POSIX
static constexpr value_type preferred_separator = '/';
#endif // filesystem model now defined
备注
在Windows的大多数上下文中,它同样允许在它的位置使用L'/'。
path::relative_path
返回 . 的 myname相对路径组件。
path relative_path() const;
备注
返回 的相对路径组件 myname,特别是 myname 删除 root_path().native() 后后缀以及任何后续冗余目录分隔符。 该组件可能为空。
path::remove_filename
删除文件名。
path& remove_filename();
path::replace_extension
替换 . 的 myname扩展名。
path& replace_extension(const path& newext = path());
Parameters
newext
新扩展。
备注
首先从中删除后缀extension().native()myname。 然后,如果 !newext.empty() && newext[0] != dot (其中 点 为 *path(".").c_str()),则将 点 追加到 myname。 然后 newext 追加到 myname。
path::replace_filename
替换文件名。
path& replace_filename(const path& pval);
Parameters
pval
文件名的路径。
备注
成员函数执行:
remove_filename();
*this /= pval;
return (*this);
path::root_directory
返回 . 的 myname根目录组件。
path root_directory() const;
备注
该组件可能为空。
path::root_name
返回 . 的 myname根名称组件。
path root_name() const;
备注
该组件可能为空。
path::root_path
返回 . 的 myname根路径组件。
path root_path() const;
备注
返回根路径组件 myname,具体 root_name() / root_directory来说。 该组件可能为空。
path::stem
返回 stem . 的 myname组件。
path stem() const;
备注
返回stem删除filename().native()任何尾随extension().native()的组件myname。 该组件可能为空。
path::string
转换存储在 . 中的 myname序列。
template <class Elem, class Traits = char_traits<Elem>, class Alloc = allocator<Elem>>
basic_string<Elem, Traits, Alloc> string(const Alloc& al = Alloc()) const;
string string() const;
备注
第一个 (template) 成员函数以与以下方式转换存储 myname 的序列:
string()用于string<char, Traits, Alloc>()wstring()用于string<wchar_t, Traits, Alloc>()u16string()用于string<char16_t, Traits, Alloc>()
第二个成员函数将存储在 myname 主机系统中的 char 编码转换为序列所青睐的编码,并返回存储在类型对象 string中的序列。
path::string_type
类型是 basic_string<value_type> 的同义词。
typedef basic_string<value_type> string_type;
path::swap
执行swap(myname, right.myname)。
void swap(path& right) noexcept;
path::u16string
将存储到 myname UTF-16 中的序列,并返回存储在类型对象 u16string中的序列。
u16string u16string() const;
path::u32string
此函数在历史 MSVC 实现中被删除。
u32string u32string() const = delete;
path::u8string
将存储在 UTF-8 中的 myname 序列转换为 UTF-8,并返回存储在类型的 u8string对象中。
string u8string() const;
path::value_type
该类型描述 path 主机操作系统所青睐的元素。
#if _WIN32_C_LIB
typedef wchar_t value_type;
#else // assume POSIX
typedef char value_type;
#endif // filesystem model now defined
path::wstring
将存储在 myname 主机系统的 wchar_t 编码中存储的序列转换为序列所青睐的编码,并返回存储在类型对象 wstring中的序列。
wstring wstring() const;