User forums > General (but related to Code::Blocks)

Sugesstion about small changes in standard cpp code.

<< < (4/6) > >>

takeshimiya:
It's the same, but in most hello world examples, it's the using namespace statement, to show that feature of C++.

Also it's ok, because the scope is in the main.cpp, and probably other functions would be there, and will be using the std namespace also.

I'd suggest to put what Stroustrup or the books put as a 'hello world' example.

me22:

--- Quote from: Takeshi Miya on September 12, 2005, 06:22:23 pm ---It's the same, but in most hello world examples, it's the using namespace statement, to show that feature of C++.

--- End quote ---

No, it's because most books about C++ are actually teaching you C ( just with cin/cout and some classes ) :x

using directives were introduced to aid in porting old code to the new standard, but none of the C++ experts ( Bjarne, Myers, Sutter, Andrescu, ... ) actually suggest using them.   using declarations are acceptable, providing their scope is limited.  ( Your main function could have using std::cout; using std::cin if all it does is deal with input and pass it off to other functions, for example. )

There's a whole lot of stuff in std:: ( which was a mistake, but that's how it is ) and you can really get bitten by it.  std headers are allowed to include whatever they want and iirc implementations are allowed to put whatever they want extra in std::, since the C++ user is technically not allowed to put anything in there.  This means that there can be all kinds of conflicting function and variable names.  Even the standard headers have functions with common names such as min, max, count, find, copy, ...

Michael:
Hello,

I have found this article "C++ Namespaces and the 'using' Directive" interesting:

http://www.bgsu.edu/departments/compsci/docs/namespaces.html

Best wishes,
Michael

Ptomaine:
What a wonderful thread I can see :)

"You can't imagine how it matters" (quot. from the "Charlie And The Chocolate Factory" movie)  :lol:

knue:
Why not build a bug in the "Hello World" template?
All beginners wil despair. :D

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version