程序错误"此文件需要ISO C ++ 2011标准的编译器和库支持"

时间:2016-04-02 22:53:27

标签: c++

此程序允许用户输入每个季节的费用,然后显示值,然后显示底部的总费用。但是,它给了我这个错误

In file included from /usr/include/c++/4.8.3/array:35:0,
                 from main.cpp:2:
/usr/include/c++/4.8.3/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \

我该如何解决这个问题?

#include <iostream>
#include <array>
#include <string>

// constant data
const int Seasons = 4;
const std::array<std::string, Seasons> Snames =
    {"Spring", "Summer", "Fall", "Winter"};

// function to modify array object
void fill(std::array<double, Seasons> * pa);
// function that uses array object without modifying it
void show(std::array<double, Seasons> da);

int main()
{
    std::array<double, Seasons> expenses;
    fill(&expenses);
    show(expenses);
    return 0;
}

void fill(std::array<double, Seasons> * pa)
{
    using namespace std;
    for (int i = 0; i < Seasons; i++)
    {
        cout << "Enter " << Snames[i] << " expenses: ";
        cin >> (*pa)[i];
    }
}

void show(std::array<double, Seasons> da)
{
    using namespace std;
    double total = 0.0;
    cout << "\nEXPENSES\n";
    for (int i = 0; i < Seasons; i++)
    {
        cout << Snames[i] << ": $" << da[i] << endl;
        total += da[i];
    }

cout << "Total Expenses: $" << total << endl;
}

1 个答案:

答案 0 :(得分:3)

阅读错误讯息!您需要使用-std=c++11-std=gnu++11进行编译。