LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2003, 06:13 PM   #1
nny0000
Member
 
Registered: Aug 2003
Distribution: Slackware, Ubuntu
Posts: 158

Rep: Reputation: 30
Understanding Namespace?


I just started learning C++, I plan on going to college and majoring in Computer Science. I just wanted to get a head start before I went. I keep hearing about using namespace std; , but I bought a book on C++ and it only touches on it. I want to understand what the purpose and format I should use it in.
Why is this needed and without it why cant the compiler compile the program?
I use to use a MSDN version of MSVC++ ( I have family in high places) and I never had to use namespace (remember I just started). So why is it different in Linux? Here I will give a quick example:

#include <iostream>
#include <stdlib.h>
#include <string>

void Printname(string first, string last);

int main(int argc , char *argv[])
{
Printname("Linus" , "Torvalds");
return 0;
}
void Printname(string first, string last)
{
String fullname = first + " " + last;
cout << fullname << endl;
}

Thanks
 
Old 12-22-2003, 06:21 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
By including the line using namespace std; at the start of your program, your can write sample C programs without having to precede the function calls with std::.

The g++ compiler will give you a warning message about using depreciated headers if you compile older sample C++ programs. If you use the newer headers instead and start the program with directive to use the standard namespace, this won't happen.
 
Old 12-22-2003, 08:45 PM   #3
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
for an excellent explanation of namespaces, see here
http://forums.devshed.com/showthread...ight=namespace
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple C++ Namespace Question kevin_cpp Programming 11 05-17-2005 05:31 PM
`cout' undeclared in namespace `std' aw_wolfe Programming 1 04-30-2005 09:25 PM
Is the C++ namespace statement no longer ANSI? scuzzman Programming 6 03-18-2005 04:53 AM
Linux 7 to 9 namespace migration issue er13b6ac Linux - Software 1 09-09-2003 05:27 AM
namespace? using? explicit? restrict? what are these? Hano Programming 3 04-11-2002 07:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration