【问题标题】:Why VS2015 intellisense shows error on C++11 user defined literals (UDL)为什么 VS2015 intellisense 在 C++11 用户定义文字 (UDL) 上显示错误
【发布时间】:2015-12-31 20:35:12
【问题描述】:

以下代码可以编译运行,但是VS2015 intellisense报错。 g++ & eclipse 有同样的问题(编译运行但显示错误)

有人知道怎么解决吗?我尝试在谷歌上搜索但没有希望。 这个错误有点烦人.. :-)

#include <iostream>
#include <thread>
#include <chrono>

using namespace std;
using namespace std::literals;
using namespace chrono_literals;

int main()
{
    this_thread::sleep_for(5s);
    cout << "test \n";

    return 0;
}

错误消息:“整数文字上的后缀 's' 无效”

非常感谢!

【问题讨论】:

  • 您在项目中使用 PCH 吗?只有这样,我们才能最终重现问题......
  • PCH 是什么意思?我刚刚在 VS2015 中新建了一个控制台项目
  • 对不起,我的意思是预编译头文件。它们在控制台项目模板中默认启用;尽管我在上面的示例中因为缺少通常的“#include ”而感到失望。

标签: eclipse c++11 visual-studio-2015 c++14 g++4.9


【解决方案1】:

您应该添加一些#include 语句和namespace 引用:

    #include <iostream>
    #include <chrono>
    #include <thread>

    int main()
    {
        using namespace std::literals::chrono_literals;

        std::this_thread::sleep_for(5s);
        std::cout << "test \n";

        return 0;
    }

在您的代码中,编译器未被告知使用命名空间std。没有std::literals5s就不行了

【讨论】:

  • Intellisense 仍然显示错误: using namespace std::literals;使用命名空间 std::chrono_literals;
  • 它不起作用。我猜是因为 VS2015 intellisense 中的一些设置。
  • 是的,我已经复制了你的观察。我不得不求助于std::this_thread::sleep_for(std::chrono::seconds(5));
  • @BrianPham 基本上,Intellisense 是愚蠢的。如果编译器没有发现错误,我倾向于忽略它:)
  • 看起来像一个错误,我们将对其进行调查。 @melak47 - 如果您在 VS2015 中发现更多问题,请通过微笑或连接发送。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-05
  • 1970-01-01
相关资源
最近更新 更多