C++ 请求数组成员时收到错误 #包括 #包括 #包括 使用名称空间std; 整数赢款[4]={0,0,0}; int*p_奖金=奖金; void CalculateGame(int*p_游戏); int main() { 国际游戏[6]={12,13,14,23,24,34}; int*p_游戏=游戏; int最喜欢的球队,比赛,球队1,球队2,得分1,得分2,i; ifstream数据(“DATA11.txt”); 数据>>喜爱的团队>>玩过的游戏; 病媒排名(4); 对于(i=0;i团队1>>团队2>>得分1>>得分2; 如果(分数1>分数2) 排名[第1组-第1组]+=3; 如果(分数1==分数2) 排名[第1-1队]++,排名[第2-1队]++; 如果(分数1

C++ 请求数组成员时收到错误 #包括 #包括 #包括 使用名称空间std; 整数赢款[4]={0,0,0}; int*p_奖金=奖金; void CalculateGame(int*p_游戏); int main() { 国际游戏[6]={12,13,14,23,24,34}; int*p_游戏=游戏; int最喜欢的球队,比赛,球队1,球队2,得分1,得分2,i; ifstream数据(“DATA11.txt”); 数据>>喜爱的团队>>玩过的游戏; 病媒排名(4); 对于(i=0;i团队1>>团队2>>得分1>>得分2; 如果(分数1>分数2) 排名[第1组-第1组]+=3; 如果(分数1==分数2) 排名[第1-1队]++,排名[第2-1队]++; 如果(分数1,c++,arrays,C++,Arrays,为什么当我请求数组游戏的一个成员(如.size()或.erase())时,我会收到一个错误,说“在非类类型int[6]的游戏中请求成员”普通的旧C数组没有成员。因此它没有大小或擦除。如果您确实希望它有成员,那么C++11提供了一个名为std::array的类,它可以通过简单地执行std::array games={…}在您的案例中使用。但是请注意,std::array没有erase成员函数,但它有一个size成员函数。使用向量会更好吗?@user1816640如果您想删除元素,可以。你必须使用“

为什么当我请求数组游戏的一个成员(如.size()或.erase())时,我会收到一个错误,说“在非类类型int[6]的游戏中请求成员”

普通的旧C数组没有成员。因此它没有
大小
擦除
。如果您确实希望它有成员,那么C++11提供了一个名为
std::array
的类,它可以通过简单地执行
std::array games={…}
在您的案例中使用。但是请注意,
std::array
没有
erase
成员函数,但它有一个
size
成员函数。

使用向量会更好吗?@user1816640如果您想删除元素,可以。你必须使用“删除”习惯用法。
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int winnings[4] = {0,0,0,0};
int* p_winnings = winnings;

void CalculateGame(int* p_games);

int main()
{
    int games[6] = {12,13,14,23,24,34};
    int* p_games = games;
    int favorite_team,games_played,team1,team2,score1,score2,i;
    ifstream data("DATA11.txt");
    data >> favorite_team >> games_played;
    vector<int> standings(4);
    for (i = 0;i < 4; i++)
        standings[i] = 0;
    for (i = 0;i < games_played;i++)
    {
        data >> team1 >> team2 >> score1 >> score2;
        if (score1 > score2)
            standings[team1 - 1] += 3;
        if (score1 == score2)
            standings[team1-1]++,standings[team2-1]++;
        if (score1 < score2)
            standings[team2-1] += 3;
        for (i = 0; i < games.size();i++)
        {
            int temp1,temp2,temp;
            temp = games[i];
            temp2 = temp % 10;
            temp /= 10;
            if (temp2 == team2 && temp == team1)
                games.erase(i);
        }
    }
}