简体   繁体   中英

Why VS2015 intellisense shows error on C++11 user defined literals (UDL)

The below code can be compiled and run, but VS2015 intellisense shows error. g++ & eclipse has the same issue (compiled & run but shows error)

Does anyone know how to fix it? I tried searching on google but hopeless. The error is a little annoying.. :-)

#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;
}

Error message: "Invalid suffix 's' on integer literal"

Thanks a lot!

You should add some #include statements and namespace references:

    #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;
    }

In your code, the compiler is not been told to use namespace std . The 5s does not work without std::literals

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM