3 Replies - 865 Views - Last Post: 18 March 2008 - 05:13 AM Rate Topic: -----

#1 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

using namespace std

Post icon  Posted 18 March 2008 - 02:34 AM

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


what is it for?
Is This A Good Question/Topic? 0
  • +

Replies To: using namespace std

#2 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1376
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: using namespace std

Posted 18 March 2008 - 02:54 AM

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:
.....
std::cout <<"Hello world!" <<std::endl;
.....



another way to do it would be to have something like:
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 =]
Was This Post Helpful? 0
  • +
  • -

#3 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

Re: using namespace std

Posted 18 March 2008 - 05:09 AM

#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:
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: using namespace std

Posted 18 March 2008 - 05:13 AM

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...namespaces.html

http://www.cprogramm...namespaces.html

http://en.wikipedia....mputer_science)

Most newer compilers will not even compile code including the non standard headers.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1