我的阵列需要一些帮助 [英] Need some help with my array
本文介绍了我的阵列需要一些帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
D:\CodeBlocks\TheRPG\Level.cpp|45|error: invalid types 'int[int]' for array subscript|
D:\CodeBlocks\TheRPG\Level.cpp|51|error: invalid types 'int[int]' for array subscript|
Level.cpp中的
in Level.cpp
<pre>#include "Level.h"
#include <iostream>
#include "Enemy.h"
#include "Data.h"
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
void Level::getID()
{
fstream fluxi("ID.txt",ios::in);
for(int i=0; i<20; i++)
{
fluxi>>ID[i]>>IDP[i]>>IDN[i];
}
fluxi.close();
system("PAUSE");
}
Level::Level()
{
}
Level::Level(float g,int e,int l ,int s)
: gold(g),exp(e),lvl(e),stage(s)
{
}
void Level::showInventory()
{
fstream fluxo("INV.txt",ios::in);
k=0;
while(!fluxo.eof())
{
fluxo>>IDO[k]>>IDPO[k]>>IDNO[k];
k++;
}
for(int i=0; i<k; i++)
{
cout<<"Item LVL:"<<IDO[i]<<" ATK:"<<IDPO[i]<<" "<<IDNO[i]<<" Sword";
}
}
void Level::addInventory()
{
fstream fluxoa("inv.txt",ios::out | ios::app);
}
void Level::editInventory()
{
fstream fluxoa("inv.txt",ios::out | ios::app);
}
void Level::stage1()
{
getID();
while(gameOver==false)
{
system("CLS");
cout<<"\n\t\tLvl:"<<lvl<<" Exp:"<<exp<<" Gold:"<<gold<<" Stage:"<<stage<<endl;
system("PAUSE");
}
}
void Level::stage2()
{
}
void Level::stage3()
{
}
Level.h中
in Level.h
#ifndef LEVEL_H
#define LEVEL_H
#include "Data.h"
#include "Enemy.h"
class Level
{
public:
Level();
Level(float g,int e,int l ,int s);
void stage1();
void stage2();
void stage3();
private:
void getInventory();
void editInventory();
void showInventory();
void addInventory();
void getID();
float gold;
int lvl,stage,exp;
int ID[21];
int IDP[21];
int IDO[21];
int IDPO[21];
int k;
char IDN[21][10];
char IDNO[21][10];
bool gameOver;
};
#endif // LEVEL_H
代码有什么问题?
我尝试了什么:
What is wrong with the code?
What I have tried:
D:\CodeBlocks\TheRPG\Level.cpp|45|error: invalid types 'int[int]' for array subscript|
D:\CodeBlocks\TheRPG\Level.cpp|51|error: invalid types 'int[int]' for array subscript|
推荐答案
我猜你使用IDN作为char数组,fluxi对象的运算符不起作用。
I guess that IDN is used by you as char array the operators of the fluxi object arent working.
for(int i=0; i<20; i++)
{
fluxi >>IDN[i]; // calls char* operator
fluxi >> i>ID[i]>>IDP[i];// calls int operator
}
提示:使用较长的变量名称可以更好地阅读(其他人)和文件的完整路径。
Tip: Use longer variables names for better reading (of other people) and a full path your the files.
这篇关于我的阵列需要一些帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文