LoginSignup
1
0

[競プロ] bits/stdc++.hがインクルードできないときの対処

Posted at

環境

Windows 10、vscode 1.87.0、mingw32 9.2.0、

症状と状況

#include<bits/stdc++.h>を書いたときに、"#include エラーが検出されました。includePath を更新してください。"というエラーが出てしまう。また、C/C++というMicrosoftが作っている拡張機能をインストールした後にエラーが出るようになった。

原因

c_cpp_properties.jsonのインクルードパスにbits/stdc++.hが含まれていなかった。また、コンパイラーなども予想していたものと異なるものが設定されていた。このファイルは、**C/C++**の設定ファイルであり、プロジェクトと同じ階層の.vscodeというフォルダの中に含まれている。

対処

自分は、mingw32をインストールしていて、g++でコンパイルしたかったため以下のようにインクルードパスを書き直した。結果、エラーが出なくなった。

c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\MinGW\\include",
                "C:\\MinGW\\lib\\gcc\\mingw32\\9.2.0\\include\\c++",
                "C:\\MinGW\\lib\\gcc\\mingw32\\9.2.0\\include\\c++\\mingw32",
                "C:\\MinGW\\lib\\gcc\\mingw32\\9.2.0\\include\\c++\\mingw32\\bits",

            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22000.0",
            "compilerPath": "cl.exe",
            "compilerPath":"C:\\MinGW\\bin\\g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4,
    
}

なお、vscode標準のsetting.jsonというファイルにて、以下のように記述するとこの設定をしなくてもよくなる。ただし、c_cpp_properties.jsonのファイルに競合する内容が記述されていた場合、後者が優先されてしまうため、注意が必要。(後者の競合する部分はコメントアウトするなどして対処する必要がある。)

setting.json
{
 //省略
"C_Cpp.default.includePath": [
        "${workspaceFolder}",
       "C:\\MinGW\\include",
       "C:\\MinGW\\lib\\gcc\\mingw32\\9.2.0\\include\\c++",
       "C:\\MinGW\\lib\\gcc\\mingw32\\9.2.0\\include\\c++\\mingw32",
       "C:\\MinGW\\lib\\gcc\\mingw32\\9.2.0\\include\\c++\\mingw32\\bits",
       "C:\\MinGW\\lib\\gcc\\mingw32\\9.2.0\\include\\c++\\mingw32\\bits\\stdc++.h",

    ],
    "C_Cpp.default.compilerPath": "C:\\MinGW\\bin\\g++.exe",
    "C_Cpp.default.cppStandard": "c++14",
    "C_Cpp.default.intelliSenseMode": "gcc-x64",
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0