Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
OK so I have this program that works correctly with g++ compiler in CodeBlocks. However, I want to modify this program and want to use the feature to_string in C++11. So I go to setting->compiler->have g++ follow c++11 ISO c++ language standard and compile and run the program. The program, which worked, doesn't work anymore. Instead, a stat.h file popped up and I got a whole list "does not name a type" errors:
_dev_t does not name a type
_ino_t does not name a type
_mode_t does not name a type
...
I don't even have _dev_t or _ino_t or any of these names in my program. I remove the to_string I just added and compiled and still those same errors appeared. What is the bug? My codes are below.

What I have tried:

File header: Container.h

C++
#ifndef CONTAINER_H
#define CONTAINER_H
#include<string>
#include<vector>
using namespace std;
class ShippingContainer
{
public:
	ShippingContainer();
	ShippingContainer(int id);
	int getId();
	void setId(int id);
	virtual string getManifest();
	virtual void setManifest();
	virtual void add();
protected:
	int IdNumber;
};
class ManualShippingContainer: public ShippingContainer
{
public:
	ManualShippingContainer();
	ManualShippingContainer(int id);
	virtual void setManifest();
	virtual string getManifest();
private:
	string manifest;
};
class RFIDShippingContainer: public ShippingContainer
{
public:
	RFIDShippingContainer();
	RFIDShippingContainer(int id);
	virtual void add();
	virtual string getManifest();
private:
	vector<string>items;
	vector<int>quantity;
};
#endif //CONTAINTER_H


File class Implementation: Container.cpp

C++
#include "Container.h"
#include<iostream>
#include<string>
using namespace std;

ShippingContainer::ShippingContainer():IdNumber(0)
{
}
ShippingContainer::ShippingContainer(int id):IdNumber(id)
{
}
int ShippingContainer::getId()
{
	return IdNumber;
}
void ShippingContainer::setId(int id)
{
	IdNumber=id;
}
string ShippingContainer::getManifest()
{
	return "";
}
void ShippingContainer::add()
{
	cout<<"do nothing\n";
}
void ShippingContainer::setManifest()
{
	cout<<"do nothing\n";
}
ManualShippingContainer::ManualShippingContainer():ShippingContainer(),manifest("")
{
}
ManualShippingContainer::ManualShippingContainer(int id):ShippingContainer(id),manifest("")
{
}
void ManualShippingContainer::setManifest()
{
	string str;
	cout<<"List what is currently inside the container\n";
	getline(cin,str);
	manifest=str;
}
string ManualShippingContainer::getManifest()
{
	return manifest;
}
RFIDShippingContainer::RFIDShippingContainer():ShippingContainer()
{
}
RFIDShippingContainer::RFIDShippingContainer(int id):ShippingContainer(id)
{
}
void RFIDShippingContainer::add()
{
	string new_item;
	getline(cin,new_item);
	if (items.size()==0)
	{
		items.push_back(new_item);
		quantity.push_back(1);
	}
	else
	{
		bool found=false;
		for (unsigned int i=0;i<items.size();i++)
		{
			if (items[i]==new_item)
			{
				found=true;
				quantity[i]++;
				return;
			}
		}
		if (!found)
		{
			items.push_back(new_item);
			quantity.push_back(1);
		}
	}
}
string RFIDShippingContainer::getManifest()
{
	string str="";
	for (unsigned int i=0;i<items.size();i++)
	{
		char x
		str=str+"10"+" "+items[i]+'\n';
	}
	return str;
}


Main program: main.cpp

C++
#include "Container.h"
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
typedef ShippingContainer* ShippingContainerPtr;
int main()
{
	ShippingContainerPtr contain[4];

	for (int i=0;i<2;i++)
	{
		contain[i]=static_cast<ManualShippingContainer*>(contain[i]);
		contain[i]=new ManualShippingContainer(i+1);
		contain[i]->setManifest();
	}
	for (int i=2;i<4;i++)
	{
		contain[i]=new RFIDShippingContainer(i+1);
		char ans;
		do
		{
			contain[i]->add();
			cout<<"anything else?\n";
			cin>>ans;
			cin.ignore(1000,'\n');
		} while (toupper(ans)!='N');
	}
	for (int i=0;i<4;i++)
	{
		cout<<contain[i]->getId()<<" "<<contain[i]->getManifest();
	}
}

Posted
Updated 13-Aug-16 1:39am

1 solution

According to this post (c++ - G++ updated on MingW gets massive error messages - Stack Overflow[^]) (and others) it might be necessary to pass the option
-std=gnu++11

instead of
-std=c++11

which is probably set by CodeBlocks.

You can try to set the option as additional parameter instead of selecting the c++11 option.

If that does not help inspect the options passed to g++ on the command line (compile output). There may be other options that reset the C++11 option.

For testing you can copy the command line for compilation of one file, modify some parameters, and execute it inside a shell.
 
Share this answer
 
Comments
ducdohuunguyen 13-Aug-16 9:13am    
Thank you for your help. I am now able to compile c++11 standard using the command line. However, the method of setting up Code Blocks for quick compilation shown in the link you show me didn't work for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900