Codeblock编译c ++ 11错误 [英] Codeblock compile c++11 error
问题描述
好的,所以我有这个程序可以正常使用CodeBlocks中的g ++编译器。但是,我想修改这个程序,并希望在C ++ 11中使用to_string功能。所以我去设置 - >编译器 - >让g ++遵循c ++ 11 ISO c ++语言标准并编译并运行程序。该计划有效,不再有效。相反,弹出一个stat.h文件,我得到一个完整列表没有命名类型错误:
_dev_t没有命名类型
_ino_t没有命名一个类型
_mode_t没有命名类型
...
我甚至没有_dev_t或_ino_t或其中任何一个名字我的节目。我删除了刚刚添加和编译的to_string,但仍然出现了相同的错误。什么是虫子?我的代码在下面。
我尝试了什么:
档案header:Container.h
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
#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
文件类实现:Container.cpp
File class Implementation: Container.cpp
#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.cpp
Main program: main.cpp
#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();
}
}
推荐答案
根据这篇文章( c ++ - 在MingW上更新的G ++会收到大量错误消息 - Stack Overflow [ ^ ])(和其他人)可能需要通过选项
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
这可能是由CodeBlocks。
您可以尝试将该选项设置为附加参数,而不是选择c ++ 11选项。
如果这对检查在命令行传递给g ++的选项没有帮助(编译输出)。可能还有其他选项可以重置C ++ 11选项。
对于测试,您可以复制命令行以编译一个文件,修改一些参数,并在shell中执行。
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.
这篇关于Codeblock编译c ++ 11错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!