Issues with iostream and std namespace?

Hey, guys! Just recently started C++ and am having an issue with compiling a simple script.

Here is the source:

#include <iostream.h>

using namespace std;

int main() {
cout << "Hello, world!";
cout << "I'm a C++ program";
return 0;
}

I'm using Mono to compile it (via gmcs) and it gives me the following errors:

hello-world.cpp(2,0): error CS1024: Wrong preprocessor directive
hello-world.cpp(3,7): error CS1041: Identifier expected: `namespace' is a keyword
hello-world.cpp(3,20): error CS1003: Syntax error, `.' expected
hello-world.cpp(5,12): error CS8032: Internal compiler error during parsing, Run with -v for details

Any ideas on why this is giving me trouble?
Last edited on
Some (all) of the errors are funky, and that last one hints that you maybe should run the compiler with -v as an argument, if you know how.

This looks like a reinstall-fixable problem, though.

-Albatross
Last edited on
well it should be <iostream>, not <iostream.h>

But your errors don't really make sense.

I didn't know Mono was a compiler? I thought it was a .net runtime environment? Are you sure you're actually using a C++ compiler?
Mono is for .Net, if you are using C++ ( ie not C# or C++/CLI ) you should use a C++ compiler
Actually, Disch++. Try compiling it with g++ and see if you get similar or the same errors. I also didn't know Mono is an actual compiler.

-Albatross
Wow, guys. That is embarrassing... thank you for all of your help. I've got gcc and have attempted to use it - it still seems like it's having an issue finding iostream. This is the output from gcc:

hello-world.c:1:20: error: iostream: No such file or directory
hello-world.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’
hello-world.c: In function ‘main’:
hello-world.c:6: error: ‘cout’ undeclared (first use in this function)
hello-world.c:6: error: (Each undeclared identifier is reported only once
hello-world.c:6: error: for each function it appears in.)
Use g++ instead of gcc or call gcc -std=c++98 -lstdc++
And remember about <iostream.h>
Last edited on
1
2
3
4
5
6
7
8
9
10
//#include <iostream.h> // NOT this!
#include <iostream> // Use this

using namespace std;

int main() {
cout << "Hello, world!";
cout << "I'm a C++ program";
return 0;	
}

Compile with:

g++ -o prog prog.cpp
Thanks a ton, everyone. That last suggestion you made fixed all of my problems, Bazzy.
Nice, Galik. Thank you! I can actually move on in the learning process now, thanks to all of you.
Topic archived. No new replies allowed.