Hi,
I wrote this simple C++ program:
Bạn đang xem: CPP First program: can't compile cout errors
#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:mingwlibgccmingw329.2.0includec++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(){
Xem thêm : Is Birria Healthy? A Nutritionist’s Take
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:UserszulfiAppDataLocalTempccalf8tU.o:test2.cpp:(.text+0x21): undefined reference to std::cout’ c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:UserszulfiAppDataLocalTempccalf8tU.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:UserszulfiAppDataLocalTempccalf8tU.o:test2.cpp:(.text+0x2d): 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> >&)’ c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:UserszulfiAppDataLocalTempccalf8tU.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:UserszulfiAppDataLocalTempccalf8tU.o:test2.cpp:(.text+0x54): undefined reference to std::ios_base::Init::~Init()’ c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:UserszulfiAppDataLocalTempccalf8tU.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
Nguồn: https://buycookiesonline.eu
Danh mục: Info
This post was last modified on November 25, 2024 7:44 pm