[英]How do I get G++ to link my header files on Linux?
I have had this problem for a while where my Linux system can't seem to link any header files(and yes, I have checked: they all exist in the right locations).我遇到这个问题已经有一段时间了,我的 Linux 系统似乎无法链接任何头文件(是的,我已经检查过:它们都存在于正确的位置)。 Here is a basic script called HelloWorld.cpp:
这是一个名为 HelloWorld.cpp 的基本脚本:
#include <iostream>
#include </usr/include/string.h>
int main(){
string hi = "Hello WOrld!";
return 0;
}
And this is the error output from the terminal:这是终端的错误输出:
HelloWorld.cpp: In function int main():
HelloWorld.cpp:5:1: error: string was not declared in this scope
string hi = "Hello WOrld!";
^~~~~~
HelloWorld.cpp:5:1: note: suggested alternative:
In file included from /usr/include/c++/8/iosfwd:39,
from /usr/include/c++/8/ios:38,
from /usr/include/c++/8/ostream:38,
from /usr/include/c++/8/iostream:39,
from HelloWorld.cpp:1:
/usr/include/c++/8/bits/stringfwd.h:74:33: note: ‘std::__cxx11::string’
typedef basic_string<char> string;
^~~~~~
What can I do?我能做什么?
你需要#include <string>
This seems like the best answer posted so far:这似乎是迄今为止发布的最佳答案:
string.h is for C-style string routines like strlen.
string.h 用于 C 风格的字符串例程,如 strlen。 You want to include (no .h), and use std::string hi = "Hello World!";
您想包含(没有 .h),并使用 std::string hi = "Hello World!"; -jkb
-jkb
Thank you for answering my question.谢谢你回答我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.