Click to See Complete Forum and Search --> : C++ Compiling problems


dvergatal666
04-21-2003, 07:19 PM
When compiling the below:

#include <iostream.h>
int main()
{
int x = 5;
int y = 7;
cout "\n";
cout << x + y << " " << x * y;
cout "\n";
return 0;
}

I get the following error(s):

# g++ project1.cpp -o project1
project1.cpp:10:2: warning: no newline at end of file
project1.cpp: In function `int main ()':
project1.cpp:6: parse error before string constant
project1.cpp:8: parse error before string constant


I'm new to C++ and the code was provided as a (supposedly working) example in a book. Can anyone tell me what's wrong?

Note; The compiler didn't compile the code into the binary after executing the command, It did however, compile the 'Hello World' program in C++ to binary but again returned the 'no newline' error as above.
Any ideas?

michaelk
04-21-2003, 07:28 PM
cout "\n"

should be

cout<<"\n";

or better yet

cout<<endl;

The last line should be blank. i.e.stick the cursor on the end of the last line of code and press the Enter key.

APwrs
04-21-2003, 07:50 PM
Just to reiterate, whenever you're using cout, you always have to pass it things with the << symbol, such as std::cout << "Hello World!"; or std::cout << x + y;.

dvergatal666
04-21-2003, 08:03 PM
Ahh I see. I've a misleading E-book. Thanks =)