Important
このページでは、<experimental/filesystem> ヘッダーによって提供される、削除されたMicrosoftの標準std::experimental::filesystem::path実装について説明します。 C++17 std::filesystem::path クラスではありません。 この事前標準実装は、 ファイル システム技術仕様 (N4100) と C++17 std::filesystemより前のバージョンに基づいています。 Microsoft Visual C++ ツールセット 14.51 以降では、<experimental/filesystem> ヘッダーとstd::experimental::filesystem名前空間が削除されます。 現在サポートされている C++17 実装については、 path クラスを参照してください。
path クラスは、string_type型のオブジェクトを格納します。ここでは、パス名として使用するのに適した、表示の目的でmyname呼び出されます。
string_typeはbasic_string<value_type>のシノニムであり、value_typeはWindowsのwchar_tのシノニムです。
構文
class path;
Constructors
| コンストラクター | Description |
|---|---|
path |
path を構築します。 |
Typedefs
| 型名 | Description |
|---|---|
const_iterator |
iterator と同義。 |
iterator |
mynameのpathコンポーネントを指定する双方向定数反復子。 |
string_type |
型は、basic_string<value_type> の同意語。 |
メンバー関数
| メンバー関数 | Description |
|---|---|
append |
指定したシーケンスを mynameに追加し、必要に応じてpreferred_separatorを変換して挿入します。 |
assign |
mynameを指定したシーケンスに置き換え、必要に応じて変換します。 |
begin |
パス名の最初のパス要素を指定する path::iterator を返します (存在する場合)。 |
c_str |
mynameの最初の文字へのポインターを返します。 |
clear |
myname.clear()を実行します。 |
compare |
比較値を返します。 |
concat |
指定したシーケンスを mynameに追加し、必要に応じて変換 (ただし、区切り記号は挿入しません) します。 |
empty |
myname.empty() を返します。 |
end |
iterator型のシーケンス末尾反復子を返します。 |
extension |
filename()のサフィックスを返します。 |
filename |
mynameのファイル名コンポーネント (具体的にはempty() ? path() : *--end()) を返します。 コンポーネントが空の場合があります。 |
generic_string |
スラッシュに変換された円記号 (Windows の下) でthis->string<Elem, Traits, Alloc>(al)を返します。 |
generic_u16string |
スラッシュに変換された円記号 (Windows の下) でu16string()を返します。 |
generic_u32string |
MSVC の過去の実装で削除されました。 |
generic_u8string |
スラッシュに変換された円記号 (Windows の下) でu8string()を返します。 |
generic_wstring |
スラッシュに変換された円記号 (Windows の下) でwstring()を返します。 |
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 |
mynameのstemコンポーネントを返します。 |
string |
mynameに格納されているシーケンスを変換します。 |
swap |
swap(myname, right.myname)を実行します。 |
u16string |
mynameに格納されているシーケンスを UTF-16 に変換し、u16string型のオブジェクトに格納されているシーケンスを返します。 |
u32string |
MSVC の過去の実装で削除されました。 |
u8string |
mynameに格納されているシーケンスを UTF-8 に変換し、u8string型のオブジェクトに格納されているシーケンスを返します。 |
value_type |
この型は、ホスト オペレーティング システムによって優先されるパス要素を記述します。 |
wstring |
mynameに格納されているシーケンスを、wchar_t シーケンスのホスト システムが優先するエンコーディングに変換し、wstring型のオブジェクトに格納されているシーケンスを返します。 |
Operators
| Operator | Description |
|---|---|
operator= |
パスの要素を別のパスのコピーに置き換えます。 |
operator+= |
さまざまな concat 式。 |
operator/= |
さまざまな append 式。 |
operator string_type |
myname を返します。 |
Requirements
ヘッダー: <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);
パラメーター
source
指定したシーケンス。
first
指定したシーケンスの先頭。
last
指定したシーケンスの末尾。
path::assign
mynameを指定したシーケンスに置き換え、必要に応じて変換します。
template <class Source>
path& assign(const Source& source);
template <class InIt>
path& assign(InIt first, InIt last);
パラメーター
source
指定したシーケンス。
first
指定したシーケンスの先頭。
last
指定したシーケンスの末尾。
path::begin
パス名の最初のパス要素を指定する path::iterator を返します (存在する場合)。
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())を返します。 2 番目の関数は myname.compare(str)を返します。 3 番目の関数は myname.compare(ptr)を返します。
int compare(const path& pval) const noexcept;
int compare(const string_type& str) const;
int compare(const value_type *ptr) const;
パラメーター
pval
比較するパス。
str
比較する文字列。
ptr
比較するポインター。
path::concat
指定したシーケンスを mynameに追加し、必要に応じて変換 (ただし、区切り記号は挿入しません) します。
template <class Source>
path& concat(const Source& source);
template <class InIt>
path& concat(InIt first, InIt last);
パラメーター
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
スラッシュに変換された円記号 (Windows の下) でthis->string<Elem, Traits, Alloc>(al)を返します。
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
スラッシュに変換された円記号 (Windows の下) でu16string()を返します。
u16string generic_u16string() const;
path::generic_u32string
この関数は、MSVC の過去の実装で削除されます。
u32string generic_u32string() const = delete;
path::generic_u8string
スラッシュに変換された円記号 (Windows の下) でu8string()を返します。
string generic_u8string() const;
path::generic_wstring
スラッシュに変換された円記号 (Windows の下) でwstring()を返します。
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;
// ...
};
注釈
このクラスは、シーケンス内のmynameのpathコンポーネントを指定する双方向定数反復子を記述します。
ルート名 (存在する場合)
ルート ディレクトリ (存在する場合)
親
pathの残りのディレクトリ要素 (存在する場合)、ファイル名 (存在する場合) で終わる
path型のオブジェクトをpvalする場合:
path::iterator X = pval.begin()は、パス名内の最初のpath要素 (存在する場合) を指定します。X == pval.end()は、Xが一連のコンポーネントの末尾を超えたときにtrueされます。*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);
パラメーター
right
pathにコピーされるpath。
source
ソース path。
注釈
最初のメンバー演算子は、 right.myname を mynameにコピーします。 2 番目のメンバー演算子は、 right.myname を mynameに移動します。 3 番目のメンバー演算子は、 *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);
パラメーター
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);
パラメーター
right
追加されたパス。
source
追加されたソース。
注釈
メンバー関数は、次の対応する式と同じように動作します。
append(right);append(source);
path::operator string_type
myname を返します。
operator string_type() const;
path::parent_path
mynameの親パス コンポーネントを返します。
path parent_path() const;
注釈
mynameの親パス コンポーネントを返します。具体的には、filename().native()を削除した後のmynameのプレフィックスと、直前のディレクトリ区切り記号を返します。 (同様に、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);
パラメーター
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)。
template<class Source> path(const Source& source, const locale& loc)
myname(source)、locから必要なcodecvtファセットを取得します。
template<class InIt> path(InIt first, InIt last)の場合はmyname(first, last)。
template<class InIt> path(InIt first, InIt last, const locale& loc)
myname(first, last)、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の相対パス コンポーネントを返します。具体的には、root_path().native()を削除した後のmynameのサフィックスと、その直後の冗長なディレクトリ区切り記号を返します。 コンポーネントが空の場合があります。
path::remove_filename
ファイル名を削除します。
path& remove_filename();
path::replace_extension
mynameの拡張機能を置き換えます。
path& replace_extension(const path& newext = path());
パラメーター
newext
新しい拡張機能。
注釈
最初に、サフィックス extension().native() を mynameから削除します。 次に !newext.empty() && newext[0] != dot ( ドット が *path(".").c_str()されている場合)、 ドット が mynameに追加されます。 次に、 newext が mynameに追加されます。
path::replace_filename
ファイル名を置き換えます。
path& replace_filename(const path& pval);
パラメーター
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
mynameのstemコンポーネントを返します。
path stem() const;
注釈
mynameのstemコンポーネントを返します。具体的には、末尾のextension().native()が削除された状態でfilename().native()されます。 コンポーネントが空の場合があります。
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;
注釈
最初の (テンプレート) メンバー関数は、 myname に格納されているシーケンスを次のように変換します。
string()(string<char, Traits, Alloc>())wstring()(string<wchar_t, Traits, Alloc>())u16string()(string<char16_t, Traits, Alloc>())
2 番目のメンバー関数は、 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
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;