簡體   English   中英

如何讓 G++ 在 Linux 上鏈接我的頭文件?

[英]How do I get G++ to link my header files on Linux?

我遇到這個問題已經有一段時間了,我的 Linux 系統似乎無法鏈接任何頭文件(是的,我已經檢查過:它們都存在於正確的位置)。 這是一個名為 HelloWorld.cpp 的基本腳本:

#include <iostream>
#include </usr/include/string.h>

int main(){
string hi = "Hello WOrld!";
return 0;
}

這是終端的錯誤輸出:

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;
                                 ^~~~~~

我能做什么?

你需要#include <string>

這似乎是迄今為止發布的最佳答案:

string.h 用於 C 風格的字符串例程,如 strlen。 您想包含(沒有 .h),並使用 std::string hi = "Hello World!"; -jkb

謝謝你回答我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM