注册 登录
编程论坛 C++教室

编译器报错不知道哪错了

a75692074 发布于 2018-07-28 16:46, 2436 次点击
程序代码:
#include <iostream>
#include <array>
#include <cstring>
using namespace std;

const int Seasons = 4;
const array<string, Seasons> Sname =
    {"Spring", "Summer", "Fall", "Winter"};

void fill(array<double, Seasons> *pa);
void show(array<double, Seasons> da);
   
int main()
{
    array<double, Seasons> expenses;
    fill(&expenses);
    show(expenses);
    return 0;
}

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

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


求大神帮忙改正一下
4 回复
#2
a756920742018-07-28 16:46
错误信息:
exercise.cpp:7:7: error: 'array' does not name a type
exercise.cpp:10:11: error: variable or field 'fill' declared void
exercise.cpp:10:11: error: 'array' was not declared in this scope
exercise.cpp:10:17: error: expected primary-expression before 'double'
exercise.cpp:10:35: error: 'pa' was not declared in this scope
exercise.cpp:11:11: error: variable or field 'show' declared void
exercise.cpp:11:11: error: 'array' was not declared in this scope
exercise.cpp:11:17: error: expected primary-expression before 'double'
exercise.cpp:11:34: error: 'da' was not declared in this scope
exercise.cpp: In function 'int main()':
exercise.cpp:15:2: error: 'array' was not declared in this scope
exercise.cpp:15:8: error: expected primary-expression before 'double'
exercise.cpp:15:8: error: expected ';' before 'double'
exercise.cpp:16:8: error: 'expenses' was not declared in this scope
exercise.cpp:17:15: error: 'show' was not declared in this scope
exercise.cpp: At global scope:
exercise.cpp:21:11: error: variable or field 'fill' declared void
exercise.cpp:21:11: error: 'array' was not declared in this scope
exercise.cpp:21:17: error: expected primary-expression before 'double'
exercise.cpp:21:35: error: 'pa' was not declared in this scope
#3
Jonny02012018-07-29 09:21
换编译器
你的编译器不支持 C++ 11
如果你的 IDE 老旧, 一般升级 IDE 可以解决问题
#4
Jonny02012018-07-29 09:22
Clang 下编译通过, gcc 没试过
#5
cnfarer2018-07-29 14:08
回复 4楼 Jonny0201
只要不是太旧的版本,GCC肯定没问题
1