using namespace std problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 33
Reputation: fzafarani is an unknown quantity at this point 
Solved Threads: 1
fzafarani's Avatar
fzafarani fzafarani is offline Offline
Light Poster

using namespace std problem

 
0
  #1
Sep 30th, 2007
Hi guys,
i have one question, when i type
using namespace std;
at top of my program my compiler gives some error
especially syntax error!
my compiler is Borland C++ v.5
for example simple code:
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <iostream.h>
  4.  
  5. using namespace std;
  6. void main()
  7. {
  8. clrscr();
  9. getch();
  10. }

Regards
Farzad Zafarani
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,859
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 55
twomers's Avatar
twomers twomers is online now Online
Posting Virtuoso

Re: using namespace std problem

 
0
  #2
Sep 30th, 2007
Shouldn't use void main. getch() isn't a great way of stopping the program. iostream.h is non-standard. use iostream:

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main( void ) {
  6.  
  7. std::cin.ignore();
  8. return 0;
  9. }
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: using namespace std problem

 
0
  #3
Sep 30th, 2007
Originally Posted by fzafarani View Post
Hi guys,
i have one question, when i type
using namespace std;
at top of my program my compiler gives some error
especially syntax error!
my compiler is Borland C++ v.5
for example simple code:
When using the old headers with .h extension you don't use "using namespace std". Check to see if your compiler supports the new headers without an extension and use those instead. The old files are out-of-date and will cause lots of other problems if you attempt to use current coding practices.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 33
Reputation: fzafarani is an unknown quantity at this point 
Solved Threads: 1
fzafarani's Avatar
fzafarani fzafarani is offline Offline
Light Poster

Re: using namespace std problem

 
0
  #4
Sep 30th, 2007
Originally Posted by twomers View Post
Shouldn't use void main. getch() isn't a great way of stopping the program. iostream.h is non-standard. use iostream:

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main( void ) {
  6.  
  7. std::cin.ignore();
  8. return 0;
  9. }
Thanks, it works, but i dont understand part of your code!
std::cin.ignore()
why you use that?!
my compiler gives error on that line?!, is it for pausing the screen?!
Regards
Farzad Zafarani
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Re: using namespace std problem

 
0
  #5
Sep 30th, 2007
Originally Posted by Ancient Dragon View Post
When using the old headers with .h extension you don't use "using namespace std". Check to see if your compiler supports the new headers without an extension and use those instead. The old files are out-of-date and will cause lots of other problems if you attempt to use current coding practices.
fzafarani here is some more info on the subject {i found it on the internet!}:
The use of namespace std for all identifiers of the C++ standard library was introduced during
the standardization process. This change is not backward compatible to old header files, in which identifiers of the C++ standard library are declared in the global scope.
In addition, some interfaces of classes changed during the standardization process (however, the goal was to stay backward compatible if possible). So, a new style for the names of standard header files was introduced. This allows vendors to stay backward compatible by providing the old header files.
i got the text from here
Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.

by Robert Frost the "The Road Not Taken"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC