-5

below is my hello world program i have written in nano editor.

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

when i compiled it, i got these many errors.

ello.cpp:4:5: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
 int main
     ^
hello.cpp:6:22: error: expected ‘}’ before ‘;’ token
  cout<< "Hello world";
                      ^
hello.cpp:6:6: error: invalid user-defined conversion from ‘std::basic_ostream<char>’ to ‘int’ [-fpermissive]
  cout<< "Hello world";
      ^
In file included from /usr/include/c++/4.8/ios:44:0,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from hello.cpp:1:
/usr/include/c++/4.8/bits/basic_ios.h:115:7: note: candidate is: std::basic_ios<_CharT, _Traits>::operator void*() const [with _CharT = char; _Traits = std::char_traits<char>] <near match>
       operator void*() const
       ^
/usr/include/c++/4.8/bits/basic_ios.h:115:7: note:   no known conversion for implicit ‘this’ parameter from ‘void*’ to ‘int’
hello.cpp:7:2: error: expected unqualified-id before ‘return’
  return 0;
  ^
hello.cpp:8:2: error: expected declaration before ‘}’ token
  }

please help me.

Umesh
  • 3
  • 2

1 Answers1

1

You missed the parentheses that mark main() as a function:

#include <iostream>

int main() {
    std::cout << "!!!Hello World!!!" << std::endl;
    return 0;
}

Note that it's much easier to understand namespaces if you explicitly use std::cout and std::endl rather than using the whole of namespace std (which can get you into confusion if you're not clear about what's going on). Alternatively, at least be clear about what you're using:

#include <iostream>

using std::cout;
using std::endl;

int main() {
    cout << "!!!Hello World!!!" << endl;
    return 0;
}
Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Mouaici_Med
  • 390
  • 2
  • 19