WAAROM IS RUIKKING NIET IN TOEKEPING

Ik heb de volgende code:

#include <string>
#include <boost/thread/tss.hpp>
static boost::thread_specific_ptr<string> _tssThreadNameSptr;

Ik krijg de volgende fout

G ++ -C -I $ BOOST_PATH TSSNAMING.H

TSSNAMING.H: 7: FOUT: ‘String’ is niet in deze scope gedeclareerd

Maar ik ben inclusief string in mijn #include.


Antwoord 1, Autoriteit 100%

U moet std::stringgebruiken, aangezien het in de stdNAMEPACE.


Antwoord 2, Autoriteit 20%

stringbevindt zich in de stdNAMEPACE. U hebt de volgende opties:

  • Write using namespace std;Na het toevoegen en alle stdInschakelen: dan kunt u alleen stringop uw programma schrijven.
  • Write using std::stringNA DE INLUSMEND OM TE INLOGEN WIJZIGING std::string: Dan kunt u alleen stringop uw programma schrijven.
  • Gebruik std::stringin plaats van string

Antwoord 3, Autoriteit 5%

Ik vind dat inclusief:

using namespace std;

Naar uw C++ -code bespaart veel tijd in het debuggen, vooral in situaties zoals de uwe waar Std :: String is vereist en ook zal het helpen bij het schoonmaken van uw code.

Met dit in gedachten moet uw code zijn:

#include <string>
using namespace std;
#include <boost/thread/tss.hpp>
static boost::thread_specific_ptr<string> _tssThreadNameSptr;

Other episodes