By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Dev c++ WTF

100+
P: 153
Well in bloodshed c++ i am able to run the following program :
Code:
#include <iostream.h>
using namespace std;

int main()
{
cout << "Hello World!" << endl;
cout << "Press any key to continue." << endl;
cin.get();
return 0;
}




I am using the .h extension which don't support namespaces and still able to run it .
what the hell ?

Also Code:
#include <iostream.h>
#include<string.h> //how can i use that ?
using namespace std; //with this ?

int main()
{
cout << "Hello World!" << endl;
cout << "Press any key to continue." << endl;
cin.get();
return 0;
}
Jun 18 '07 #1
Share this Question
Share on Google+
4 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
#include <iostream.h>
#include<string.h> //how can i use that ?
using namespace std; //with this ?
You have to decide:
1) Am I using non_ANS C++ (C++ prior to 1998)
or
2) Am I using ANS/ISO C++
??

If (1), you use iostream.h, you can never use namespaces and you must put up with the C++ bugs of 10 years ago. This does not implement the complete C++ language.

If (2), you use iostream and the std namespace.

None of this has to do with using string.h. This is a header for C. If (2), you should be using cstring. ANS/ISO C++ header file names have no extension. The .h means a C header.

your code should be:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream> 
  2. #include<cstring> 
  3. using namespace std; 
  4.  
  5. int main() 
  6. cout << "Hello World!" << endl; 
  7. cout << "Press any key to continue." << endl; 
  8. cin.get(); 
  9. return 0; 
  10. }
  11.  
Of course, in C++ you do not use the C string functions. You use the STL string template.
Jun 18 '07 #2

P: 86
string.h is a C header and not the the same as the c++ header <string>. The equivalent c++ header would be <cstring>

iostream.h is a deprecated c++ header, but obviously still supported in dev c++/mingw. The easiest answer to your question of why it works would be to open iostream.h and see what's inside.
Jun 18 '07 #3

100+
P: 153
What u r saying is correct.
But still i am able to run the following program.
The compiler is not showing any error.

#include <iostream.h> //OLD HEADER
using namespace std; //NEW CONCEPT (NOT SUPPORTED BY .H extension)

int main()
{
cout << "Hello World!" << endl;
cout << "Press any key to continue." << endl;
cin.get();
return 0;
}
Jun 19 '07 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
What u r saying is correct.
But still i am able to run the following program.
The compiler is not showing any error.

#include <iostream.h> //OLD HEADER
using namespace std; //NEW CONCEPT (NOT SUPPORTED BY .H extension)
Your version of Dev C++ is very old and does not support ANS/ISO C++. Implementing the std namespace in iostream.h was an attenpt to avoid havng all the Dev C++ users change all their code from iostream.h to iostream.

I would get a newer more compliant compiler.
Jun 19 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.