error messages

Hi
Can someone help?

#include <iostream>
using namespace std;
int main( )
{ cout << "Hello world" >>; return 0;}
Instead of
cout << "Hello world" >>;

should be either

cout << "Hello world";

or

cout << "Hello world" << endl;
Remove the >>.
Hey, welcome to cplusplus forums.
When posting code, please use code tags which can be found to the right of the text box (the <> symbol, click it).

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main( )
{ 
    cout << "Hello world" >>; //this is your error. 
    return 0;
}


cout does not define operator >>.

You need to change it to this:
 
cout << "Hello World"; //remove >> altogether. 
Thanks for pointing the error but i still can not come right
What is the error you are receiving?
Here is the list, for interest sake does it matter which windows are you using?

#include <iostream>
using namespace std;
int main()
{cout << "Hello world"; return 0; }

C:\Program Files (x86)\UNISA\COS1511\Activity 1a.ii\Hello world1.c|1|error: iostream: No such file or directory|
C:\Program Files (x86)\UNISA\COS1511\Activity 1a.ii\Hello world1.c|2|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'|
C:\Program Files (x86)\UNISA\COS1511\Activity 1a.ii\Hello world1.c||In function 'main':|
C:\Program Files (x86)\UNISA\COS1511\Activity 1a.ii\Hello world1.c|4|error: 'cout' undeclared (first use in this function)|
C:\Program Files (x86)\UNISA\COS1511\Activity 1a.ii\Hello world1.c|4|error: (Each undeclared identifier is reported only once|
C:\Program Files (x86)\UNISA\COS1511\Activity 1a.ii\Hello world1.c|4|error: for each function it appears in.)|
||=== Build finished: 5 errors, 0 warnings ===|
What compiler and IDE are you using?
It's likely that one or the other isn't configured properly, because it's not finding default C++ headers.
Last edited on
IDE and C++ compiler
If you want to compile the code as C++ the extension of the file must be a C++ extension. For example, either .cpp or .cc - just putting .c will cause the compiler to interpret the file as C and not C++
Last edited on
Hello Thumper, I have saved my file as .cpp not as .c which seems to be a default on my programme and the results is the error below.

#include <iostream>
using namespace std;
int main( )
{
cout << "Hello world"; return 0; }
}#include <iostream>
using namespace std;
int main( )
{
cout << "Hello world"; return 0; }
}
Error\Untitled1.cpp|6|error: expected declaration before '}' token|
Is it a typo that the code is duplicated?


It is the compiled message should be:

#include <iostream>
using namespace std;
int main( )
{
cout << "Hello world"; return 0; }
}

Error Activity 1a.ii\Untitled1.cpp|6|error: expected declaration before '}' token|
The closing brace in line #6 shall be removed.

#include <iostream>
using namespace std;
int main( )
{
cout << "Hello world"; return 0; } // <== remove it
}
Thanks it worked, if i may ask
why changed the file default to .cpp?
shouldnt i work it on the default e.g. untitled1.c as it was given in the book?
it could if you explicitly tell your compiler that it is the c++ file.
Read your compiler help tj learn how.
Topic archived. No new replies allowed.