-
What's the difference?
Hi all,
I was wondering, whatīs is the difference between:
#include <iostream>
#include <cstring>
and using
#include <iostream.h>
#include <string.h>
I mean, donīt they do the same thing? I know the first ones are known as standard headings. Which is better to use?
Thanks in advance.
And yes, Iīve searched the forum.
-
The first are better if you are going to be programming in C++, those are now standard. Things are in namespace std with the no .h headers, while they aren't with the oldstyle headers including the .h.
Conform to the standard, use the new style headers.
-
>whatīs is the difference between
The first two are current C++ headers and are subject to new additions to the language. If you want to program in correct ISO standard C++ then use the new headers.
>Which is better to use?
If you have access to the current headers then use them instead of the older ones.
-Prelude
-
Ok, thanks. Now I know I should use the 'no .h headers'. I've also seen that with the new ones you have to put
using namespace std;
and std::out or things like that. Is there a website that explains it or can you do it in the post?
TIA
-
A namespace is pretty much a set of names that have been declared in the program at some point. It's a container and every library is only supposed to declare things in its own namespace. I guess for orginazation. "std" is the standard library namespace.
So, if you wanted to use 'cout' of the std namespace, you do:
Code:
using namespace std;
cout << "blah" << endl;
OR
Code:
std::cout << "blah" << endl;
The difference is that when you have 'using namespace std;', it puts you in that namespace so that functions you call are checked from there and you don't have to prefix them with std::.
You can declare your own namespaces, as so:
Code:
namespace MyNewNameSpace {
void function();
int variable;
};
Hope this helps.
-
Thanks a lot. It's all clear now. I will be creating my new programs according to the standard now.