943,973 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 25709
  • C++ RSS
Sep 30th, 2007
0

using namespace std problem

Expand 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:
c++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
fzafarani is offline Offline
33 posts
since Aug 2007
Sep 30th, 2007
0

Re: using namespace std problem

Shouldn't use void main. getch() isn't a great way of stopping the program. iostream.h is non-standard. use iostream:

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main( void ) {
  6.  
  7. std::cin.ignore();
  8. return 0;
  9. }
Reputation Points: 453
Solved Threads: 57
Posting Virtuoso
twomers is offline Offline
1,873 posts
since May 2007
Sep 30th, 2007
0

Re: using namespace std problem

Click to Expand / Collapse  Quote originally posted by fzafarani ...
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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Sep 30th, 2007
0

Re: using namespace std problem

Click to Expand / Collapse  Quote originally posted by twomers ...
Shouldn't use void main. getch() isn't a great way of stopping the program. iostream.h is non-standard. use iostream:

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Light Poster
fzafarani is offline Offline
33 posts
since Aug 2007
Sep 30th, 2007
0

Re: using namespace std problem

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!}:
Quote ...
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
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ support for Graphics.h
Next Thread in C++ Forum Timeline: write and delete details on csv file in C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC