-
using 'using'
on my comp at home (a linux box) i don't have to use "using std::cout; " but on the system at school (HP UNIX) i do. Is this just system dependent? BTW, i am using g++ is both cases.
Also someone told me to always use "using namespace std". I haven't yet, and everthing has gone pretty good so for...
-
If you have an uptodate compiler, then you should use the newer namespace savy headers (<instream> not <iostream.h>....) instead. And if you do so, you will need to use the using keyword.
If you "using std::cout;" as you said, then you are telling the compiler thgat whenever I call cout, I am refering to the cout that's part of the std namespace........so effectively, everytime it sees "cout" it recognises it for "std::cout" before compilation
Now if you use "using namespace std", you are basically dragging the whole of namespace std into the global namespace.....so its just as if you used the old style headers!...good for quick examples and experiments....not too wise for full applications (assuming you want to work with namespaces in your code)
-
thanks fordy.
One more question, what is the difference between <iostream> and <iostream.h> besides the fact old compilers use <iostream.h>. For example why do you need <iostream> if you have to use "using" anyway? And when you use <cstring> do you need any "using" statements?
-
<iostream> is <iostream.h> but wrapped inside the std namespace.......so therefore if I wanted to design a new type of cin....if I used <iostream.h> I would get a compiler error,as there would be 2 cin's....but if I used namespaces I could
Code:
#include <iostream>
using std::cout;
#include <fordy.h>
using fordy::cin;
Then I can use my cin and the normal cout without errors (well....in truth if I designed a cin I bet there would be whole load of errors :p)
-
thanks for the explanation, you get my vote.