gpt4 book ai didi

c++ - 我怎样才能使 Eclipse C.D.T.认识 C++11 的特性?

转载 作者:太空狗 更新时间:2023-10-29 23:04:32 28 4
gpt4 key购买 nike

请在将其标记为重复之前阅读此问题!

这个问题不是 this question 的重复问题或 this questionthis question ,虽然是相关的。我已经解决了所有这些问题以及更多问题。我有同样的基本问题,但我已经尝试了我找到的所有解决方案,但这些其他问题的解决方案都不适合我。

问题是 Eclipse C.D.T.不识别许多 C++ 标准函数和特性。这些无法识别的功能大部分来自 C++11。无法识别的功能包括关键字 nullptr、变量 NULL 和函数 to_string(), getLine(), fstream.open(), atoi(), strcmp()stricmp() 等。

在名为 leeduhem 的用户和其他人的帮助下,我设法将 -std=c++11 标志添加到 Eclipse 的 g++ 编译器命令中,因此错误在编译过程中消失了。

但是,Eclipse 仍然会用红色下划线标记这些方法和符号,并将它们标记为错误。

所以,总而言之,我的问题是:

如何让 Eclipse 识别代码编辑器中的 C++11 函数和符号?

我已经尝试了上面链接问题中的所有解决方案以及Eclipse's C++11 F.A.Q.中的解决方案。有和没有 this forum post 中提到的修改.仍然没有任何效果。

我最近在我的计算机上安装了带有 C/C++ 插件的 NetBeans,试图通过切换 I.D.E. 来解决这个问题,但是 NetBeans 有完全相同的错误

我在 Linux Mint 16 Petra 上运行 Eclipse 3.8。我的主要编译器是 GCC/G++ 4.8.1,不过我相信我也可以使用 Cygwin。

这是有错误的代码示例:

#include <stdio.h>
#include <string>
#include <string.h>

using namespace std;

HubNode* hubs;

void debug();
void menu();

// main
int main() {
// initialize hubs
hubs = NULL;

// read Hub.csv
fstream hub_in;
hub_in.open("Hub.csv", ios::in);
if (!hub_in.is_open()) {
cout << "I couldn't open the Hub.csv file!";
return -1;
}
string read_name = "", read_location = "";
// skip the first line
getLine(hub_in, read_name);
if (read_name.empty()) {
cout << "The Hub.csv file was empty!";
return -1;
}
// then continue reading
while (getLine(hub_in, read_name, ',')) {
getLine(hub_in, read_location, '\n');
addHub(new HubNode(read_name, read_location));
}

// read Flight.csv
fstream flight_in;
flight_in.open("Flight.csv", ios::in);
if (!flight_in.is_open()) {
cout << "I couldn't open the Flight.csv file!";
return -1;
}
string read_number = "", read_price = "", read_source = "",
read_destination = "", read_minute = "", read_hour = "", read_day =
"", read_month = "", read_year = "", read_duration = "",
read_company = "";
// skip the first line
getLine(hub_in, read_number);
if (read_number.empty()) {
cout << "The Hub.csv file was empty!";
return -1;
}
// then continue reading
while (getLine(flight_in, read_number, ',')) {
getLine(flight_in, read_price, ',');
getLine(flight_in, read_source, ',');
getLine(flight_in, read_destination, ',');
getLine(flight_in, read_minute, '/');
getLine(flight_in, read_hour, '/');
getLine(flight_in, read_day, '/');
getLine(flight_in, read_month, '/');
getLine(flight_in, read_year, ',');
getLine(flight_in, read_duration, ',');
getLine(flight_in, read_company, '\n');
FlightNode* flight = new FlightNode(read_number,
atof(read_price.c_str()), read_company,
new Date_Time(atoi(read_minute.c_str()),
atoi(read_hour.c_str()), atoi(read_day.c_str()),
atoi(read_month.c_str()), atoi(read_year.c_str())),
atoi(read_duration.c_str()), read_source, read_destination);
}

cout << "Welcome to Ground Control! How may I assist you?";
menu();
string input;
cin >> input;
cin.ignore();
while (strcmp(input.c_str(), "q") != 0) {
if (strcmp(input.c_str(), "p") == 0)
debug();
else {
// TODO
}
cin >> input;
cin.ignore();
}
cout << "Have a nice flight!";

return -1;
}

// message utilities
void debug() {
HubNode* hub = hubs;
while (hub != NULL)
cout << hub->toString();
}

void menu() {
cout << "cmd | description";
cout
<< " p | prints the full list of airport hubs with all of their currently scheduled flight information";
// TODO
}

// Hub-managing utilities
bool addHub(HubNode* hub) {
// if hubs is null, make this hub the new head
if (hubs == NULL) {
hubs = hub;
return true;
}

// otherwise, find the end of the hubs list and add this hub to the end
HubNode* parser = hubs;
while (parser->next != NULL) {
// along the way, make sure this hub isn't already in the list
if (strcmp((parser->getName()).c_str(), (hub->getName()).c_str()) == 0)
return false;
parser = parser->next;
}
parser->next = hub;
return true;
}

HubNode* findHub(string name) {
HubNode* parser = hubs;
while (parser != NULL) {
if (strcmp((parser->getName()).c_str(), name.c_str()) == 0)
return parser;
parser = parser->next;
}

return NULL;
}

bool removeHub(HubNode* hub) {
return removeHub(hub->getName());
}

bool removeHub(string name) {
// check the first node alone first
if (hubs == NULL)
return false;
else if (strcmp((hubs->getName()).c_str(), name.c_str()) == 0) {
HubNode* to_remove = hubs;
hubs = hubs->next;
delete to_remove;
return true;
} else if (hubs->next == NULL)
return false;

HubNode* parser = hubs;
while (parser->next != NULL) {
if (strcmp((parser->next->getName()).c_str(), name.c_str()) == 0) {
HubNode* to_remove = parser->next;
parser->next = parser->next->next;
delete to_remove;
return true;
}
parser = parser->next;
}

return false;
}

有什么想法吗?

提前感谢您提供的任何帮助。在这一点上我非常绝望。这个问题极大地阻碍了我在 C++ 类项目上的进展,而且我几乎没有足够的经验来尝试在没有 I.D.E. 的情况下编写代码。 (我试过了。)

编辑:似乎有一些函数在从终端编译时甚至 g++ 都无法识别,例如stricmp()。我还不确定是否还有其他人,尽管它似乎能够理解 to_string 和其他一些人。不过,我的 G++ 版本是 4.8.1,这几乎是最新的稳定版本....这会导致 Eclipse 和 NetBeans 中的错误吗?

最佳答案

Eclipse 和 NetBeans IDE 很可能必须具有更新的解析器和词法分析器细节才能正确支持 C++11。希望有人已经为 C++11 完成了这项工作,并且可以发布更多详细信息。

NetBeans 似乎是用 Java 编写的,因为该产品的论坛有三个帖子讨论了较旧和较新 NetBeans 版本的过程。

开始编辑
我找到了一个非 Eclipse 帖子,它可能是 Eclipse IDE 中 C++11 关键字识别的解决方案。点评:How do I use a custom gcc toolchain with Eclipse? .它具有用于在 Eclipse 中更新 GCC toochain 的分步过程和屏幕截图。我希望 CLang 和 CLang++ 编译器的支持设置是相似的。外部文章来自此 SO 帖子:Eclipse IDE for C++ hooking up multiple compiler toolset
结束编辑

我现在没有更多时间按照 NetBeans 程序创建新的 NetBeans 解析器和词法分析器以支持 C++11。也许其他人已经这样做了,可以分享细节。我找到的帖子如下。请注意,这些教程适用于 NetBeans IDE 中的任何语言。

上述两个步骤必须按此顺序进行。如果不是,我不知道会发生什么,但可能不是预期的结果。

我希望有更多完整的帖子。也许其他用户只是忽略了 IDE 中不正确的关键字指示。 NetBeans 7.4 似乎非常适合使用 CLang++ 3.3 编译器进行编译。我在以 C++11 为中心的项目上没有 C++11 编译错误。 IDE 错误地指出 override 无效。

关于c++ - 我怎样才能使 Eclipse C.D.T.认识 C++11 的特性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22669809/

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