请求数组成员时收到错误
Receiving an error when requesting members for an array
#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);
}
}
}
为什么当我请求数组游戏的成员(如 .size(( 或 .erase(( (时,我收到一条错误消息,说"在非类类型 int [6] 的游戏中请求成员__">
普通的
旧 C 数组没有成员。所以它没有size
或erase
.如果你确实希望它有成员,C++11 提供了一个名为 std::array<T,N>
的类,只需执行std::array<int, 6> games = { ... }
即可在您的情况下使用。但请注意,std::array
没有 erase
成员函数,但它具有size
成员函数。
相关文章:
- "错误:数组下标的无效类型'float [10001][float]'是什么意思?
- 错误:数组下标的类型"const bool[int]"无效
- Qt并发错误:数组初始化需要大括号括起来的初始值设定项列表
- 使用GCC 4.8构建错误:数组用作初始化器
- 如何修复问题中的"teminated due to timeout"错误 数组操作 |黑客兰克?
- | 9 |错误:非静态数据成员'matrix :: row'| 9 |错误:数组绑定不是在']']'令牌|之前的整数常数
- 错误:数组的总大小不得超过0x7fffffff字节
- 错误:无法将参数“1”的“double*”转换为“double”,错误:数组下标的类型“double[double]”无
- 返回并强制转换数组指针(错误:数组下标的类型..无效)
- 返回c++中的字符错误数组
- VC++错误:数组实例化的大小来自模板化的静态常量
- c++mex错误:数组下标的类型“double[mwSize]”无效
- 错误数组用作初始值设定项,我不知道错误
- 编译错误 - 数组下标'char[int]'的类型无效
- 向量在我的类中.错误:数组new [-fpermissive]中的圆括号初始化项
- 错误:数组下标的类型无效
- 错误:数组new中的size必须是整型[-fpermissive]
- 错误:数组下标的“Pixel*[__complex__ int]”类型无效
- c++错误数组显示
- C++:错误:数组下标的类型“size_t{aka long unsigned int}[size_t{aka long