why is string not declared in scope

前端 未结 3 1674
时光取名叫无心
时光取名叫无心 2020-12-09 03:15

I have the following code:

#include 
#include 

static boost::thread_specific_ptr _tssThreadNameSptr;
         


        
相关标签:
3条回答
  • 2020-12-09 03:47

    I find that including:

    using namespace std;
    

    To your C++ code saves a lot of time in debugging especially in situations like yours where std:: string is required and also it will help in keeping your code clean.

    With this in mind, your code should be:

    #include <string>
    using namespace std;
    #include <boost/thread/tss.hpp>
    
    static boost::thread_specific_ptr<string> _tssThreadNameSptr;
    
    0 讨论(0)
  • 2020-12-09 03:49

    You have to use std::string since it's in the std namespace.

    0 讨论(0)
  • 2020-12-09 03:50

    string is in the std namespace. You have the following options:

    • Write using namespace std; after the include and enable all the std names: then you can write only string on your program.
    • Write using std::string after the include to enable std::string: then you can write only string on your program.
    • Use std::string instead of string
    0 讨论(0)
提交回复
热议问题