Please read this question before marking it as a duplicate!
This question is not a duplicate of this question or this question or this question, though it is related. I have been through all of these questions and many more. I have the same basic problem, but I have tried all the solutions I have found and none of the solutions to these other questions have worked for me.
The issue is that Eclipse C.D.T. does not recognize many C++ standard functions and features. Most of these features that are not recognized are from C++11. Unrecognized features include the keyword nullptr
, the variable NULL
, and the functions to_string()
, getLine()
, fstream.open()
, atoi()
, strcmp()
, stricmp()
, and more.
With the help of a user named leeduhem and others, I managed to add the -std=c++11
flag to Eclipse's g++
compiler command, so the errors during compilation disappeared.
However, Eclipse still underlines these methods and symbols in red and marks them as errors.
So, my question, in summary, is:
How can I get Eclipse to recognize C++11 functions and symbols in the code editor?
I have tried all the solutions in the questions linked above as well as the solution in Eclipse's C++11 F.A.Q. with and without the modification mentioned in this forum post. Still, nothing works.
I recently installed NetBeans on my computer with the C/C++ plugin to try and remedy the issue by switching I.D.E.s, but NetBeans had the exact same errors.
I am running Eclipse 3.8 on Linux Mint 16 Petra. My primary compiler is GCC/G++ 4.8.1, though I believe I also have Cygwin available.
Here is a sample of the code that is having errors:
#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;
}
Any ideas?
Thank you in advance for any help you can provide. I'm pretty desperate at this point. This issue has greatly hindered my progress on a C++ class project and I am not nearly experienced enough to try and code in it without an I.D.E. (I've tried.)
EDIT: It seems that there are a few functions that even g++
can't recognize when compiling from the terminal, e.g. stricmp()
. I am yet unsure if there are any others, though it seems to be able to understand to_string
and some others. My G++ version is 4.8.1, though, which is almost the latest stable version.... Could this be causing the errors in Eclipse and NetBeans?