ファイルパスは文字列として渡されます。この文字列を std :: filesystem :: path に変換するにはどうすればよいですか?例:
#include <filesystem>
std::string inputPath = "a/custom/path.ext";
const std::filesystem::path path = inputPath; // Is this assignment safe?
はい、この構造は安全です:
const std::filesystem::path path = inputPath; // Is this assignment safe?
これは割り当てではなく、コピーの初期化です。これを呼び出しています コンストラクター :
template< class Source >
path( const Source& source );
かかる:
ソース(4)によって提供される文字シーケンス(ポインターまたは入力イテレーター)から、ヌル終了文字/ワイド文字シーケンスan
std::basic_string
またはstd::basic_string_view
、
だからあなたは元気です。さらに、filesystem::path
からstd::string
を作成できなかった場合、本当に奇妙になります。