Hi,
I found that I have to use g++ compiler:
D:\CPP programs>g++ test2.cpp D:\CPP programs>
Running the output
D:\CPP programs>a.exe Hello World D:\CPP programs>
Zulfi.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I wrote this simple C++ program:
#include <iostream>
int main(){
cout<<"Hello World"<<std::endl;
return 0;
}
It gives me following errors
D:\CPP programs>gcc test2.cpp test2.cpp: In function 'int main()': test2.cpp:3:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'? 3 | cout<<"Hello World"<<std::endl; | ^~~~ | std::cout In file included from test2.cpp:1: c:\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:61:18: note: 'std::cout' declared here 61 | extern ostream cout; /// Linked to standard output | ^~~~ D:\CPP programs>
Then I wrote the following:
#include <iostream>
int main(){
std::cout<<"Hello World"<<std::endl;
return 0;
}
I got the following errors
D:\CPP programs>gcc test2.cpp c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\zulfi\AppData\Local\Temp\ccalf8tU.o:test2.cpp:(.text+0x21): undefined reference to
std::cout' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\zulfi\AppData\Local\Temp\ccalf8tU.o:test2.cpp:(.text+0x26): 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*)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\zulfi\AppData\Local\Temp\ccalf8tU.o:test2.cpp:(.text+0x2d): undefined reference tostd::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\zulfi\AppData\Local\Temp\ccalf8tU.o:test2.cpp:(.text+0x34): undefined reference to
std::ostream::operator<<(std::ostream& (*)(std::ostream&))' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\zulfi\AppData\Local\Temp\ccalf8tU.o:test2.cpp:(.text+0x54): undefined reference tostd::ios_base::Init::~Init()' c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\zulfi\AppData\Local\Temp\ccalf8tU.o:test2.cpp:(.text+0x75): undefined reference to
std::ios_base::Init::Init()' collect2.exe: error: ld returned 1 exit status D:\CPP programs>
Somebody please guide me.
Zulfi
Hi,
I found that I have to use g++ compiler:
D:\CPP programs>g++ test2.cpp D:\CPP programs>
Running the output
D:\CPP programs>a.exe Hello World D:\CPP programs>
Zulfi.