How to compile the code using #include

后端 未结 3 1286
渐次进展
渐次进展 2021-01-05 08:20

I am trying to compile some C++ code that uses threads:

#include 
#include 
void hello()
{
    std::cout<<\"Hello Concurr         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 08:39

    and standard threading support is a new feature (defined in the C++11 standard). As for g++, you have to enable it adding -std=c++0x to the command line, as explained in the error message.

    Also, you are using a nonstandard (Microsoft-specific) main, use the "classic" main and normal char:

    // thread1.cpp
    #include 
    #include 
    
    void hello()
    {
        std::cout<<"Hello Concurrent World\n";
    }
    
    int main(int argc, char * argv[])
    {
        std::thread t(hello);
        t.join();
    
        return 0;
    }
    

    Notice that not all C++11 features are available in current compilers; as far as g++ is concerned, you can find the status of their implementation here.

提交回复
热议问题