Hey i saw buzz's c++ tutorials ...
In those tuts in the first program they've written a program like this [ theyre using Visual Studio.net ]
#include%26lt;iostream.h%26gt;
using std::cout;
{
cout%26lt;%26lt;"Hello";
}
And in the tutorials when they run the program without the
" using std::cout; "
command, they arent able to run it
whereas i dont need to type in that command to run the program in Turbo C++ or Visual studio..
So can any one tell me that what is the command for ? And is it only used in visual studio.net or what ???
C++ query ...?
using std::cout imports the cout function from the std namespace into your local name space. std is the namespace that much of the Standard Template Library is stored in. Google "C++ STL namespace" and you'll see what I mean. You could change
using std::cout;
to:
using namespace std;
and it would import the whole standard library into your local namespace. Importing the namespace (or function as your tut shows) allows you to make a call to the function directly. If you did not import the function or namespace, you would have to change the code from the tutorial to look like this:
#include%26lt;iostream.h%26gt;
{
std::cout%26lt;%26lt;"Hello";
}
See how we're prefacing the cout call with the namespace in which it resides?
The "using" command is standard across all newer C++ compilers. As you program you might use a third party library that has a different namespace. In that case you'd use something like:
using thirdpartylibrarynamespace::thirdpartyfu...
{
thirdpartyfunction();
}
and I'm sorry but the other answer is wrong. It is indeed
cout %26lt;%26lt; "Hello";
Reply:I'm not a c++ expert, but I think it means you can only use the cout%26gt;%26gt; thing inside the using std::cout braces...
Plus its cout%26gt;%26gt; not cout%26lt;%26lt;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment