关于C++11以下头文件限制的解决

Dev-C++由于其基于较旧的C++97标准,导致部分现代C++头文件无法使用,如<cstdint>和<array>。当尝试使用这些新功能时,会因缺少C++11支持而报错。解决方案是转向VS2022,选择C++桌面开发并安装SDK以获得完整头文件支持。另外,Dev-C++可通过配置改为支持C++11标准。
摘要由CSDN通过智能技术生成

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>,但是该头文件不常用,而且后来还删掉了,所以不提及)

报错图片:

0332bc1830654eff8a1cbe02148b457c.png

里面有一句话:

#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

 报错图片:

a28ddb131a7f484e9a32e1b6d14c6191.png

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的博客-CSDN博客的错误,不然你会像我一样后悔莫及),以便头文件的正常使用

如图: 

0c2591bc528d4aa3945093e62aa5dc37.png

需要2中的头文件时,就可以使用VS了。不会?请看教程:visual studio新手使用教程_vs如何开始编程_平头哥阿威的博客-CSDN博客

2023.5.22完善:

但是,我几天前看了一个人的文章,原来Dev-C++可以调成C++11的!!!

具体操作,我不想说了,参见如何更改C语言标准_c语言修改_H.Y_C ⁹⁹⁹⁹⁹⁹⁺的博客-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值