I’m using in my code many namespaces including the std one , so when I want to declare a string variable in my code should I precise std::string or I can just put string :
#include <string.h>
using namespace std;
using namespace boost;
using namespace xerces;
int main()
{
/*! should I declare my str like this */
std::string str;
/*! or I can declare it like this */
string str1;
cout << str << str1 <<endl;
return 0;
}
Since you have
using namespace std;, the namestringmeans the same asstd::string[*]. It’s therefore a question of style which you prefer (and if you preferstd::stringthen you can leave outusing namespace std;).There are some name clashes between
std::andboost::, in particular for things that were trialled in Boost prior to standardization. So for example if you include the appropriate headers then bothstd::shared_ptrandboost::shared_ptrexist. They may or may not refer to the same type, I haven’t checked whether Boost tries to detect the standard type before defining its own.So it’s not necessarily a good idea to use both
stdandboostnamespaces at the same time. You can use individual names withusing std::string;, instead of the whole namespace.[*] if
std::stringis defined, which it isn’t, since you didn’t include<string>.