如何将字符串转换为文件系统路径?

时间:2018-09-21 00:20:54

标签: c++ linux

我想让用户输入要程序复制并粘贴到的文件的源和目标。我正在使用Linux,但不包含标准文件系统,因此必须使用实验性/文件系统。 编译时出现错误。我看过类似的帖子:Convert a string to std filesystem pathexperimental::filesystem linker error,但它们没有帮助。

我正在运行的代码:

#include <iostream>
#include <string>
#include <experimental/filesystem>
#include <exception>


namespace fs = std::experimental::filesystem;

int main(){
    char choice = ' ';

    do{
        std::string sourceFileString;
        std::string destFileString;

        std::cout<<"Enter the address of the file you want to copy: "<<std::endl;
        std::cin>>sourceFileString;
        std::cout<<"Enter the destination folder you want to copy the file to: "<<std::endl;        
        std::cin>>destFileString;

        const fs::path sPath = sourceFileString;

        std::cout<<"Enter R  to repeat the program: ";
        std::cin>>choice;
    }while(choice == 'r' || choice == 'R');


    return 0;
}

我尝试编译时遇到的错误:

    /tmp/ccMmFEED.o: In function `std::experimental::filesystem::v1::__cxx11::path::path<std::__cxx11::basic_stri
ng<char, std::char_traits<char>, std::allocator<char> >, 
std::experimental::filesystem::v1::__cxx11::path>
(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
 const&)':
    main.cpp:
(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2INSt7__cxx1112basic_stri
ngIcSt11char_traitsIcESaIcEEES3_EERKT_[_ZNSt12experimental10filesystem2v17__cxx1
14pathC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES3_EERKT_]+0x70):
 undefined reference to 
`std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'


    collect2: error: ld returned 1 exit status

任何帮助将不胜感激。

0 个答案:

没有答案