Header files in Linux

Dec 16, 2008 at 7:09pm
I recently installed Ubuntu on a PC, and I got code::blocks for it. The problem is that even when I declare header files I still have to point to the functions using the std::. Does this mean I should just do using namespace std instead? Or is there something I'm doing wrong?

Example
1
2
3
4
5
6
#include <iostream>
int main() {
cout << "Words";
std::cout << "words";
return 0;
}


line 3: cout was not declared in this scope


Dec 16, 2008 at 8:38pm
Technically you should use using namespace std; anyways if you're using cout, or at least using std::cout;
AFAIK nothing automatically causes it to use std by default.
Dec 16, 2008 at 11:23pm
No no what I mean is that in Windows the header file <iostream> includes the stream functions, so I never needed using namespace std in the first place; but Ubuntu doesn't seem to acknowledge it.

No worries I understand what the issue is now. Thanks
Last edited on Dec 16, 2008 at 11:25pm
Dec 17, 2008 at 12:42am
That's sort of weird...now i'm interested.
<iostream> includes the commands, but it doesn't automatically make it so you're using namespace std;
What compiler were you using?
Dec 17, 2008 at 5:53am
The only standard library I know of where cout is not in the std namespace is VC++ 6.0, because it's previous to the 1998 standard. It's likely all older compilers are like that, as well.
Any compiler that lets you use cout without specifying using namespace or without std::cout, is wrong, and you should not use it for new projects.
Dec 17, 2008 at 7:08am
Yea i was using VC6, so I never ever declared the std namespace in my programs for anything.
Dec 17, 2008 at 7:13am
You'll also find that you can now do things like this:
1
2
3
4
5
6
for (int a=0;a<n;a++){ //a declared once...
	//...
}
for (int a=0;a<n;a++){ //OMG! a declared again! And no compiler error!
	//...
}
Topic archived. No new replies allowed.