如何使Eclipse cd识别c++ 11特性

How can I make Eclipse C.D.T. recognize C++11 features?

本文关键字:c++ 特性 识别 cd 何使 Eclipse      更新时间:2023-10-16

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

这个问题不是这个问题、这个问题或这个问题的重复,尽管它们是相关的。我已经解决了所有这些问题以及更多的问题。我也有同样的基本问题,但我已经尝试了所有我能找到的解决方法,但没有一个对我有效。

问题在于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的c++ 11 faq中的解决方案,无论是否有本论坛帖子中提到的修改。

我最近在我的电脑上安装了带有C/c++插件的NetBeans,试图通过切换id来解决这个问题,但是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++类项目中的进展,我没有足够的经验去尝试在没有id的情况下编写代码(我已经尝试过了)。

EDIT: 从终端编译时,似乎有几个函数连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关键字识别的解决方案。回顾:如何在Eclipse中使用自定义gcc工具链?它提供了在Eclipse中更新GCC toochain的分步过程和屏幕截图。我希望CLang和clang++编译器集的支持是相似的。外部文章来自这个SO帖子:Eclipse IDE for c++连接多个编译器工具集
结束编辑

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

  • NetBeans 7.2及以上版本
    1) JavaCC词法生成器集成教程的NetBeans平台
    2) JavaCC解析器生成器集成教程

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

  • NetBeans 7.1及更早版本
    如何创建对新语言的支持

我希望有更完整的帖子存在。也许其他用户只是忽略了来自ide的错误关键字指示。NetBeans 7.4与clang++ 3.3编译器一起编译似乎非常好。在以c++ 11为中心的项目中,我没有遇到c++ 11编译错误。IDE不正确地说override是无效的。