c++ - 与 4.7 g++ 不一致的文字

标签 c++

我对代码中的简单定义有很大的疑问。我已经从 Mozilla 错误站点报告中了解到有关修复的信息,但它对我的情况不起作用。

代码的原始部分(当然它在 4.6 中有效):

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#define A "A: %20"PRIu64

error: inconsistent user-defined literal suffixes ’A’ in string literal

修复后:

#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#define A "A: %20" PRIu64

error: inconsistent user-defined literal suffixes ’A’ in string literal

还有什么建议吗?

最佳答案

我建议升级到更高版本的 g++ - 您的两种形式的代码在 5.4 版本中都可以正常工作:

#include <iostream>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#define A "A: %20"PRIu64
#define B "B: %20" PRIu64

int main() {
    std::cout << A << std::endl;
    std::cout << B << std::endl;
}

关于c++ - 与 4.7 g++ 不一致的文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18271726/

相关文章:

c++ - 如何将 `std::vector` 成员变量 move 到方法的调用者?

c++ - 排序几乎已排序的大文件

c++ - 指向具有 vector 内存泄漏的对象的指针

c++ - 表达式未计算为 C++ VS 中的常量

c++ - std::string 与 unordered_sets 一起使用时是否需要哈希函数?

c++ - CMake 错误 : MYSQL_INCLUDE_DIR not found

c++ - 对右值的引用(右值的地址)

c++ - Qt C++错误没有匹配函数调用 'QString::QString(KeySequence)'

c++ - 是否有一个 std::variant 包含所有变体

c++ - 在 C++ lamdas 和 QTimer 上。这个警告是什么意思,如何消除它?