gpt4 book ai didi

c++ - 极端新手 - Hello World 错误

转载 作者:太空宇宙 更新时间:2023-11-04 14:56:50 24 4
gpt4 key购买 nike

使用 B. Stroustrup 的编程文本和关于第 50 页的“hello world”程序会出错。我对“std_lib_facilities.h”包含文件有疑问。

运行(作为 root)'gcc hworld1.cpp' 后输出是 -

In file included from /usr/include/c++/4.4/ext/hash_map:60,
from std_lib_facilities.h:34,
from hworld1.cpp:1:
/usr/include/c++/4.4/backward/backward_warning.h:28: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated.
/tmp/ccpwXUYx.o: In function `main':
hworld1.cpp:(.text+0x14): undefined reference to `std::cout'
hworld1.cpp:(.text+0x19): 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*)'
/tmp/ccpwXUYx.o: In function `__static_initialization_and_destruction_0(int, int)':
hworld1.cpp:(.text+0x41): undefined reference to `std::ios_base::Init::Init()'
hworld1.cpp:(.text+0x46): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccpwXUYx.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

关于如何修复文件的任何建议,或许注释掉散列部分?

很高兴终于有时间开始了,但这似乎比第一个故障排除任务要大一些。我试过只使用 iostream 作为包含。我在 Ubuntu 11.04 上运行它。也许我需要更新 gcc 或使用 g++。不确定什么能让我轻松度过这一关。我尝试了一些使用“使用...标准”和...作为我不记得的适当名称的方法(哎呀)。任何人都只知道正确的包括。

这是代码-

#include "std_lib_facilities.h"

int main()
{
cout<<"hiya people\n";
return 0;
}

最佳答案

你应该使用 g++,因为 gcc 是 C 编译器(不是 C++)。

关于c++ - 极端新手 - Hello World 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8466755/

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