命名空间'std'中没有名为 'u16string' 的类型
No type named 'u16string' in namespace 'std'
我使用的是QT 5.5.0。
当我编译一个程序时,它显示"在命名空间'std'中没有名为'u16string'的类型"。有趣的是,我过去成功地编译了它,为什么现在失败了?似乎是qstring.h
有问题。
我该如何修复它?这里是错误发生的地方
#ifndef QSTRING_H
#define QSTRING_H
#if defined(QT_NO_CAST_FROM_ASCII) && defined(QT_RESTRICTED_CAST_FROM_ASCII)
#error QT_NO_CAST_FROM_ASCII and QT_RESTRICTED_CAST_FROM_ASCII must not be defined at the same time
#endif
#include <QtCore/qchar.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qrefcount.h>
#include <QtCore/qnamespace.h>
#include <string>
#if defined(Q_OS_ANDROID)
// std::wstring is disabled on android's glibc, as bionic lacks certain features
// that libstdc++ checks for (like mbcslen). namespace std { typedef basic_string<wchar_t> wstring; }
#endif
#if defined(Q_COMPILER_UNICODE_STRINGS) || defined(Q_QDOC)
static inline QString fromStdU16String(const std::u16string &s);
inline std::u16string toStdU16String() const;
static inline QString fromStdU32String(const std::u32string &s);
inline std::u32string toStdU32String() const;
#endif
修复:
-
由于mac上的Qt是由clang构建的,在"Qt Creator"->"Preferences"->"Kits"中,你应该将"Compiler"设置为clang。
-
而不是写"QMAKE_CXXFLAGS += -std=c++11",添加以下配置到你的.pro文件:
CONFIG += c++11
有趣的是,我在过去成功地编译了它,为什么它现在失败了?
之前你应该包含一些库的头文件,而这些头文件又包含<string>
;这个,在一些更新之后,可能会停止直接包括它,从而出现错误。
如何修复?
在源代码中包含适当的头文件,以避免此类问题。
#include <string>
在发生错误的翻译单元中,并确保使用命名空间:std::u16string
.
问题是在文件ExpGame.pro.I删除代码如下:
QMAKE_CXXFLAGS += -std=c++11
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 模板元程序查找相似的连续类型名称
- 是否可以从int转换为enum类类型
- 构造函数正在调用一个使用当前类类型的函数
- 我应该使用什么来代替void作为变体中的替代类型之一
- 命名空间'std'中没有名为 'u16string' 的类型