Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,926 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,802 people online right now. Registration is fast and FREE... Join Now!




using namespace std

 
Reply to this topicStart new topic

using namespace std

red_4900
18 Mar, 2008 - 01:34 AM
Post #1

Code T(h)inkers
****

Joined: 22 Feb, 2008
Posts: 827



Thanked: 11 times
My Contributions
ok. I've seen in many tutorial, many books suggesting the code to have something like this:
CODE
.....
using namespace std;
....


what is it for?
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Using Namespace Std
18 Mar, 2008 - 01:54 AM
Post #2

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,551



Thanked: 98 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
The std namespace has all of the typical things that you'd expect to use within a program. (like cout, cin, endl, etc)

If you wasn't using namespace std;, your program would look something like this:
CODE

.....
std::cout <<"Hello world!" <<std::endl;
.....


another way to do it would be to have something like:
CODE
using std::cout;
using std::cin;



This only uses the features which you wish to use in your program.

I hope this clears it up =]
User is offlineProfile CardPM
+Quote Post

red_4900
RE: Using Namespace Std
18 Mar, 2008 - 04:09 AM
Post #3

Code T(h)inkers
****

Joined: 22 Feb, 2008
Posts: 827



Thanked: 11 times
My Contributions
CODE
#include<iostream.h>
int main(){
cout<<"yo\n";
return 0;
}


compiled nicely without error and still run smoothly. and I didnt even use the std namespace. unsure.gif
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Using Namespace Std
18 Mar, 2008 - 04:13 AM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,228



Thanked: 40 times
Dream Kudos: 25
My Contributions
Very true, but the code you've written does not comply to accepted ANSI standards. It is non portable. the iostream.h library has been deprecated (as have many .h libraries) in the move towards namespaces. This article may explain the matter.

http://www.cplusplus.com/doc/tutorial/namespaces.html

http://www.cprogramming.com/tutorial/namespaces.html

http://en.wikipedia.org/wiki/Namespace_(computer_science)

Most newer compilers will not even compile code including the non standard headers.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:22PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month