【发布时间】:2015-07-17 08:19:34
【问题描述】:
我正在使用 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
【问题讨论】:
-
如果您发布代码会很有用,请
-
@PaoloM #如果定义(Q_COMPILER_UNICODE_STRINGS)|| defined(Q_QDOC) 静态内联 QString fromStdU16String(const std::u16string &s);内联 std::u16string toStdU16String() const;静态内联 QString fromStdU32String(const std::u32string &s);内联 std::u32string toStdU32String() const; #endif
-
你加入了
<string>吗?查看更多代码会很有帮助。也许编辑您的问题,而不是将代码作为评论发布。 -
@muXXmit2X 代码太长,大约有 1500 个低点。
-
@shengfuzou 好吧,因为
u16string是在c++ 标头string中定义的,所以您需要包含该标头。确保在您使用u16string的文件中包含#include <string>行