Line 5: error: expected unqualified-id before '{' token|

I can't see the problem with this code, can anyone tell me what I am doing wrong?

1
2
3
4
5
6
7
8
9
#include <iostream>


int main();
{
cout main <<"GET OUT OF HERE, YOU DISGUST ME!\n";
   return 0;
}

Last edited on
The first thing I come to think of is that the program is kind of rude, that could be a problem.

What is cout main supposed to do?
Oh crap, I think I made a typo then, I fixed it

1
2
3
4
5
6
7
8
#include <iostream>


int main();
{
   cout <<"GET OUT OF HERE, YOU DISGUST ME!\n";
   return 0;
}


and it still does not work, still I get the same error.

EDIT: I am using code blocks to make this, if you are wondering. I doubt it matters though
Last edited on
I fixed it, apparently the ebook I am learning from leaves out the "std::" from "std::cout", can you explain why?
I also made a typo in line 4, it should not have a semicolon, the ebook is correct there, that was my mistake.

According to the book:
1
2
3
4
5
6
7
#include <iostream.h>

 int main()
{
cout << "Hello World!\n";
return 0;
}


Also, what does the "\n" denote?
Last edited on
You should just put the std:: on there, it's good practice to. If you *really* don't want to, you can place using namespace std; above main.

The \n is a special character that represents a newline.
Why does the ebook not show std then? Explain that.
I did not not put it there on purpose, the ebook did not state that I put it there, the way you say it is as if I did not put it there because I was too lazy to.
Last edited on
As I said, they have using namespace std;, so that you bring everything from std:: (like cout) into the global namespace.
And I am supposed to know this? The ebook that I am learning from did not mention "using namespace std;" or even a simple "std::cout", that is why I had the problem in the first place, I did not not put it there on purpose as you are seemingly suggesting, the damn resource I am learning from did not make the "std::cout" apparent, it left "std::" out, I am just asking why it would do that, a simple error or otherwise I'd like to know so I can be confident in continuing using this resource that I am learning C++ from.

(And yes, I meant to say "not not", that wasn't a mistype).

Link to ebook\pdf: www.angelfire.com/art2/ebooks/teachyourselfcplusplusin21days.pdf
Seems to be good, has 772 pages, doesn't necessarily look like bullshit. Yes the title seems suspect, I am not sure I will really learn all of it (C++) it in 21 days, of course, only what is in the ebook.
Last edited on
It looks like the book is old, and the use of <iostream.h> with .h at the end suggest it's from before C++ was standardized which happened 1998 (17 years ago). That's why it differs somewhat from the C++ we use today.
As you're still in the early stages of learning C++ from that book, I would advise you to change, judging from what was left out (in your posts).

http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list

Go to that website and find the recommended books. :)
Ok, I will check the link out, thanks.
Last edited on
Topic archived. No new replies allowed.