-
using namespace std;
Code:
// This is the Hello World program (HelloWorld.cpp)
// Note: You should always start with a description of your program here.
// Written by: Colin Goble
// Note: Please put your name here or both names if you are working in a pair.
// Date: 19 June 2005
// Note: Put the current date here
// Sources: None
// Note: Always cite all sources you may have used, such as other students you
// may have had help from, web sites you may have referenced, and so forth.
// If none, write None.
// The next few lines are standard boilerplate you will need...
// ...in front of virtually every C++ program you will write this term.
#include <iostream> //Required if your program does any I/O
using namespace std; //Required for ANSI C++ 1998 standard.
int main ()
{
char reply;
cout << "Hello World" << endl;
// This section stops the program 'flashing' off the screen.
cout << "Press q (or any other key) followed by 'Enter' to quit: ";
cin >> reply;
return 0;
}
I have never heard of using namespace std; being required for any standards... Anyone else?
-
I think it means that this:
Code:
cout << "Hello World" << endl;
requires that you use the std namespace. As opposed to pre-C++98 stuff in which cout was not in the std namespace.
-
Yes. The comment is wrong.
With the new (c++ 98) headers, as Dave explained, the std namespace was introduced to the standard library. Three techniques are used to reach these objects.
(in order of preference)
1. Explicit access (for example std::cout << "hello world" << std::endl;)
2. Using declarations (for example using std::cout; )
3. Using directives (for example using namespace std; )
Of the three techniques, it is in fact the third that is the least recommended and may eventually lead to name clashes. Whereas the first technique is the fail safe one and most recommended. As such, that comment seems to endorse the use of the worst of the three techniques.
What the comment is trying to tell you is that you do need to access iostream objects (and other objects from other headers) through the std namespace in order to comply with the C++ standards. You do this by defining your headers in the new style (between < and >, and without the h extension).
-
Oh I know what using namespace std; does, just never heard of it being a requirement... :D
-
Well, it is a requirement... for compliance with the standards
-
The namespace is required, but that statement
Code:
using namespace std;
is not required.
-
As far as I know, using namespace std is required if you want to use the C++ functions of the <iostream> library (like cin, cout, cerr). If you just use C functions like printf() or scanf(), you don't have to type it in.
-
Please read what has been said before. Not. It's not required.
-
Sorry!
I just wanted to help.
-
well, if u didnt use the statement/command: using namespace std; u would have to put it at the start of ur statements.
example:
Code:
cout << (would become:)
std: :cout<<
if i have posted anything wrong, let me no
:)
-
Beene, please don't answer an old thread with something that was not asked. But worst, with an answer that is wrong.
is malformed.
the scope operator has no space between each colon.
-