it can be used to access class function and namespaces
for example :
1 2 3 4 5 6 7 8 9
namespace abc {
int variable;
};
int main(){
cin >> abc::variable;
}
for std::string
it means that there is namespace called std and there is a class or a variable or whatever it is that is named string
but for std::string it is a class
:: is the scope resolution operator, and allows you to statically traverse scopes such as namespaces and classes in order to reference the identifier you want.
Class string is in namespace std, so you can access it in a variety of ways:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <string>
namespace x = std;
namespace y
{
namespace z = std;
}
int main()
{
std::string a;
::std::string b;
x::string c;
y::z::string d;
using std::string;
string e;
}
Note that you should never write usingnamespace std; or anything similar.