Undefined reference to `std::cout'

My code is print only cout<<“HelloWord”<<endl; but I got errors below. Just to let you know that I am using university cluster for writing codes.

helloworld.C:(.text+0xa): undefined reference to `std::cout'
helloworld.C:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
helloworld.C:(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
helloworld.C:(.text+0x1c): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/l/ccdXz0WQ.o: In function `__static_initialization_and_destruction_0(int, int)':
helloworld.C:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
helloworld.C:(.text+0x59): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status

Put following two lines on the top of your code.

#include < iostream >
using namespace std;

please refrain from sprinkling code with using namespace std;, especially in headers.
that’s bad practice.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.