簡體   English   中英

無法編譯 c++ 包含文件系統的程序

[英]Cannot compile c++ program including filesystem

我寫了一個非常簡單的 c++ 程序:

#include<filesystem>
using namespace std::filesystem;

int main(){
    return 0;
}

起初,我用

g++ -c main.cpp -o main.o

並出現以下錯誤:

main.cpp:2:22: error: 'filesystem' is not a namespace-name
 using namespace std::filesystem;
                  ^~~~~~~~~~
main.cpp:2:32: error: expected namespace-name before ';' token
 using namespace std::filesystem;
                                ^

我讀到我只需要將 -std=c++17 放在 -c 之后即可編譯 c++17 中的所有新內容。
但是當我這樣做時,我會收到數百個錯誤,例如:

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
|| (__p.has_root_name() && __p.root_name() != root_name()))

要么

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: At global scope:
C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:511:18: error: specialization of 'std::filesystem::__cxx11::path::__is_encoded_char<wchar_t>' after instantiation
 struct path::__is_encoded_char<wchar_t> : std::true_type  

還有很多。 誰能告訴我我做錯了什么。 庫和編譯器與 codeBlocks 安裝程序一起下載,因此它們通常應該是正確的。
先感謝您!

no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')

這是 mingw 8.1.0 中的錯誤。 錯誤報告: https://sourceforge.net/p/mingw-w64/bugs/737

這在 9.x 版本中已修復,您需要將 mingw 升級到更新版本 (9.0+)

我寫了一個非常簡單的 c++ 程序:

#include<filesystem>
using namespace std::filesystem;

int main(){
    return 0;
}

起初,我用

g++ -c main.cpp -o main.o

並得到以下錯誤:

main.cpp:2:22: error: 'filesystem' is not a namespace-name
 using namespace std::filesystem;
                  ^~~~~~~~~~
main.cpp:2:32: error: expected namespace-name before ';' token
 using namespace std::filesystem;
                                ^

我讀到我只需要在 -c 之后放入 -std=c++17 即可編譯 c++17 中的所有新內容。
但是當我這樣做時,我會收到數百個錯誤,例如:

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
|| (__p.has_root_name() && __p.root_name() != root_name()))

或者

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: At global scope:
C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:511:18: error: specialization of 'std::filesystem::__cxx11::path::__is_encoded_char<wchar_t>' after instantiation
 struct path::__is_encoded_char<wchar_t> : std::true_type  

還有很多。 誰能告訴我我做錯了什么。 庫和編譯器是使用 codeBlocks 安裝程序下載的,因此它們通常應該是正確的。
先感謝您!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM