2012-09-01 137 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

相關問題