954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

What is "std" and "::"

What is "std" and "::" .Like for example, std::cout. Now i know what is cout for but what is std and what are these "::" for?

Diamond3x
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

std is a system-level namespace. If you want to set the namespace for a section of code, you can do so with the "using namespace " directive. IE:

using namespace std;

int foo(int value)
{
    cout << "value==" << dec << value << endl;
}

Without the "using" directive, you'd have to do this:

int foo(int value)
{
    std::cout << "value==" << std::dec << value << std::endl;
}

That said, a lot of standard C++ header files will do the "using namespace std;" for you, which is why you often don't see the "std::" part of these elements.

rubberman
Posting Virtuoso
1,564 posts since Mar 2010
Reputation Points: 277
Solved Threads: 179
 
Now i know what is cout for but what is std and what are these "::" for?


The :: operator is called the scope resolution operator. It's primarily there for accessing names declared in a namespace or class, and std is the C++ library's namespace. std::cout says to look for cout in the std namespace and fail if it's not there.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

Thanks guys for the answer

Diamond3x
Newbie Poster
2 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

So, std is a namespace?
And how we know the syntax inside std?

kuadran45
Newbie Poster
8 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 
So, std is a namespace?


Yuppers.And how we know the syntax inside std?
I don't understand the question.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 
I don't understand the question.


Forgive me, i am a novice in C++ language. :)
I mean "coutt" is inside std isn't?
so, are there another function(beside coutt) inside std?

kuadran45
Newbie Poster
8 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 
so, are there another function(beside coutt) inside std?


Everything in the standard C++ library is wrapped inside the std namespace.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 
Everything in the standard C++ library is wrapped inside the std namespace.

So, well.. thankyou very much!

kuadran45
Newbie Poster
8 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: