1
我有这样的一个下面添加一个整数一个struct
“不兼容的类型中的
int
至int [10000]
分配”
我不明白什么是错的错误。这里是我的代码:
#include<fstream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
struct words{
string lexis;
int sizes[10000];
} a[10000];
bool s(const words& a,const words& b);
//==========================================
int main() {
int i,x;
string word;
//input-output with files
ifstream cin("wordin.txt");
ofstream cout("wordout.txt");
i = 0;
//reading until the end of the file
while(!cin.eof()){
cin >> word;
x = word.size();
a[i].sizes = x; //the problem is here
a[i].lexis = word;
i++;
}
}
我真的很感激,如果有人帮助我。 :) 感谢
做**不**使用'cin.eof()'作为循环读取输入的主要条件。另外,使用'while(cin >> word){...}' –
'a [i] .sizes'产生一个int(&)[10000]',检查任何输入_after_读和_before_。你可以给'a [i] .sizes [j]'分配一个'int'。 –
你确定你想要10000个10000个数组的数组吗? IT看起来你的结构在使用方面没有很好的定义。不要在C++中使用原始数组,请使用更方便的向量(动态数组)。 –