5 Replies - 350 Views - Last Post: 22 May 2010 - 02:14 PM Rate Topic: -----

#1 maxpower1991  Icon User is offline

  • New D.I.C Head

Reputation: -14
  • View blog
  • Posts: 33
  • Joined: 21-May 10

some help with this

Posted 22 May 2010 - 11:05 AM

using namespace std;

in linked list code
what this mean??? :look:
Is This A Good Question/Topic? 0
  • +

Replies To: some help with this

#2 SpeedisaVirus  Icon User is offline

  • Baller
  • member icon

Reputation: 114
  • View blog
  • Posts: 855
  • Joined: 06-October 08

Re: some help with this

Posted 22 May 2010 - 11:09 AM

This


(The very bottom of the page explains why its std.)

This post has been edited by SpeedisaVirus: 22 May 2010 - 11:11 AM

Was This Post Helpful? 0
  • +
  • -

#3 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 113
  • View blog
  • Posts: 688
  • Joined: 16-February 09

Re: some help with this

Posted 22 May 2010 - 11:10 AM

In C++, there is namespaces and scope. The purpose for this is to keep things organized.

In the STL, everything is in the std scope: std::cout. Basically, it is a shortcut that allows you to omit the namespace (but still keep things right).

Without using namespace std; the similar code would be required:
std::cout << "This is a line\n";
std::cout << "This is another line\n";
std::cout << "What is your name? ";
std::cin >> name;



To shorten the code, you could modify it like so:
using namespace std;

cout << "This is a line\n";
cout << "This is another line\n";
cout << "What is your name? ";
cin >> name;



Learn about C++ from: http://cplusplus.com
Was This Post Helpful? 1
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: some help with this

Posted 22 May 2010 - 11:14 AM

It is called a namespace. Think of it as a special naming context (or container) which helps protect against name collisions...that is, two functions being named the same. If I declare a function called sqrt() and later you create one called sqrt() and they end up in the same project, we are going to have issues. However, if I create mine in a namespace called "Martyr2" and you create yours in one called "maxpower" then they can appear in the same file side by side. How we would determine which is which is then we would qualify it. To use mine I would use Martyr2::sqrt() and you would use maxpower::sqrt().

So using namespace std means that the file is currently using function version from the namespace called "std". We could leave that line out and use the qualified name like std::string or std::cout. Or we could leave it in and simply use "string" and "cout" since it is assumed we are using versions from the std namespace.

Read up more on the idea of namespaces and you will get the idea. :)
Was This Post Helpful? 1
  • +
  • -

#5 maxpower1991  Icon User is offline

  • New D.I.C Head

Reputation: -14
  • View blog
  • Posts: 33
  • Joined: 21-May 10

Re: some help with this

Posted 22 May 2010 - 12:42 PM

View PostMartyr2, on 22 May 2010 - 05:14 PM, said:

It is called a namespace. Think of it as a special naming context (or container) which helps protect against name collisions...that is, two functions being named the same. If I declare a function called sqrt() and later you create one called sqrt() and they end up in the same project, we are going to have issues. However, if I create mine in a namespace called "Martyr2" and you create yours in one called "maxpower" then they can appear in the same file side by side. How we would determine which is which is then we would qualify it. To use mine I would use Martyr2::sqrt() and you would use maxpower::sqrt().

So using namespace std means that the file is currently using function version from the namespace called "std". We could leave that line out and use the qualified name like std::string or std::cout. Or we could leave it in and simply use "string" and "cout" since it is assumed we are using versions from the std namespace.

Read up more on the idea of namespaces and you will get the idea. :)


thank you....thats helpfully :D
and thank you all
Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: some help with this

Posted 22 May 2010 - 02:14 PM

Moderator Note:
DreamInCode user hint -- if you find a post helpful you can click on the green Posted Image button on the bottom right of each post. We encourage user to click this button when a post is helpful to you or the poster really went above and beyond to help another member.

If a post was NOT helpful you can select the red Posted Image button. Please be a little considerate when using this button as marking someone down might make them a little mad. So if you honestly feel that the post did not contribute to the conversation or was too confusing to be any help what-so-ever then mark it down.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1