Dev-C++相信许多人都听说过,它是一个不错但是也有bug的IDE编译器。
1.Dev-C++的限制
它有一种限制:部分头文件无法使用(最常用的V5.11,C++97版本),比如:<cstdint>,<array>等等。
为什么呢?因为它的C++标准太老了(Dev-C++是C++97,而现在都C++17了)
根本报错原因是因为头文件<bits/c++0x_warning.h>(有的是<bits/c++14x_warning>,但是该头文件不常用,而且后来还删掉了,所以不提及)
报错图片:
里面有一句话:
#if __cplusplus < 201103L
#error This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.
#endif
那么魔改<bits/c++0x_warning.h>可以吗?显然不行,因为有些无法在Dev-C++中使用,比如VS中经常蹦出来的宏定义改版:
constexpr auto hongdingyigaiban = true
//=#define hongdingyigaiban true
报错图片:
2.受影响的头文件:
因为 #if __cplusplus > 201103L 该条件不满足于Dev-C++,所以使用<bits/stdc++.h>时它会自动避开不符合要求的头文件,避免发生报错(<bits/c++0x_warning>),所以以下头文件将不会包括:
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cuchar>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
3.解决方案
下载VS2022,选择“使用C++的桌面开发”,然后记得勾选SDK(不要犯我在VS2022无法打开“windows.h”或“conio.h”、“stdio.h”等头文件该怎么办?_无法打开源文件windows.h_cppxj12345的博客-优快云博客的错误,不然你会像我一样后悔莫及),以便头文件的正常使用
如图:
需要2中的头文件时,就可以使用VS了。不会?请看教程:visual studio新手使用教程_vs如何开始编程_平头哥阿威的博客-优快云博客
2023.5.22完善:
但是,我几天前看了一个人的文章,原来Dev-C++可以调成C++11的!!!
具体操作,我不想说了,参见如何更改C语言标准_c语言修改_H.Y_C ⁹⁹⁹⁹⁹⁹⁺的博客-优快云博客