gpt4 book ai didi

c++ - 编译卡在先前的编译C++中

转载 作者:行者123 更新时间:2023-12-02 10:00:31 25 4
gpt4 key购买 nike

   #include <iostream>
#include <fstream>
#include <string>

using namespace std;



int main() {

cout << "Hello";

}
当我尝试编译该程序时,它仍然会编译最后一个程序:
  #include <iostream>
#include <fstream>
#include <string>

using namespace std;


int main() {

int a, b;
cin >> a >> b;
cout << a + b << endl;

return 0;
}
我在命令提示符下执行gcc code.cpp(文件名)和代码,出现:
     c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: 
C:\Users\User\AppData\Local\Temp\cctefhtT.o:code.cpp:(.text+0x19): undefined reference to
`std::cout'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:
C:\Users\User\AppData\Local\Temp\cctefhtT.o:code.cpp:(.text+0x1e): 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\User\AppData\Local\Temp\cctefhtT.o:code.cpp:(.text+0x35): undefined reference to
`std::ios_base::Init::~Init()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:
C:\Users\User\AppData\Local\Temp\cctefhtT.o:code.cpp:(.text+0x56): undefined reference to
`std::ios_base::Init::Init()'
collect2.exe: error: ld returned 1 exit status
我的编辑是崇高的。

最佳答案

您正在查看先前程序的结果,因为新程序的编译失败。
程序编译失败的原因是,您的程序取决于C++标准库中的代码。您的程序未与C++标准库链接,因为您使用gcc(它是C的编译器)。您需要使用g++(它是C++的编译器)。

关于c++ - 编译卡在先前的编译C++中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62727882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com