gpt4 book ai didi

C++ Primer(第5版)初学者的困惑

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:37:50 31 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
GCC linker can’t find standard library?

我想弄乱我在假期得到的这本 C++ 书,我对 Python 的了解有限,所以这些东西对我来说真的很奇怪。

我将第一课中的这段代码输入到我的文本编辑器中,并将其保存为 .cpp 文件。

#include <iostream>
int main()
{
std::cout << "Enter two numbers:" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2
<< " is " << v1 + v2 << std::endl;
return 0;
}

但是当我尝试编译它时,我的终端给出了这个疯狂的输出,这是怎么回事?

Raymond-Weisss-MacBook-Pro:c++ Raylug$ gcc prog2.cpp
Undefined symbols for architecture x86_64:
"std::basic_istream<char, std::char_traits<char> >::operator>>(int&)", referenced from:
_main in cckdLEun.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in cckdLEun.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in cckdLEun.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in cckdLEun.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in cckdLEun.o
"std::cin", referenced from:
_main in cckdLEun.o
"std::cout", referenced from:
_main in cckdLEun.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in cckdLEun.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in cckdLEun.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Raymond-Weisss-MacBook-Pro:c++ Raylug$

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