2012-09-01 71 views
14

宣布我有以下代码:为什么不串范围

#include <string> 
#include <boost/thread/tss.hpp> 

static boost::thread_specific_ptr<string> _tssThreadNameSptr; 

我收到以下错误

g++ -c -I$BOOST_PATH tssNaming.h

tssNaming.h:7: error: 'string' was not declared in this scope

但我包括我的#include字符串。

+2

之前的字符串 – innochenti

+1

可能重复添加的std :: [C++错误: '串' 尚未声明】(http://stackoverflow.com/questions/2890860/c-错误字符串还没有被宣布) – juanchopanza

回答

32

您必须使用std::string,因为它位于std名称空间中。

+0

Tys,工作! – Jimm

6

string位于std命名空间中。您有以下选择:

  • using namespace std;后,包括和启用所有std名称:那么你只能string在你的程序编写。
  • using std::string包含后启用std::string:那么你可以在你的程序上只写string
  • 使用std::string而不是string
+1

您应该谨慎使用'using namespace std'或'using std :: string'并将其放在一个有界的范围内(例如,在一个函数中)。切勿在标题中使用它,因为它会使用标题的用户可能不想要的符号来污染全局名称空间。 – alexc

相关问题