我不能为了我的生活找出为什么这不起作用。我不得不对文件中的单词列表进行频率检查,并且在读取它们时,我试图检查当前单词是否与字符串数组中的元素相对应,并确保它们在我之前不等于添加它。代码如下:检查从文件读入数组中的字符串
fin.open(finFile, fstream::in);
if(fin.is_open()) {
int wordArrSize;
while(!fin.eof()) {
char buffer[49]; //Max number chars of any given word in the file
wordArrSize = words.length();
fin >> buffer;
if(wordArrSize == 0) words.push_back(buffer);
for(int i = 0; i < wordArrSize; i++) { //Check the read-in word against the array
if(strcmp(words.at(i), buffer) != 0) { //If not equal, add to array
words.push_back(buffer);
break;
}
}
totNumWords++; //Keeps track of the total number of words in the file
}
fin.close();
这是一个学校项目。我们不允许使用任何容器类,所以我构建了一个结构来处理扩展char **数组,推回和弹出元素等。
@Alex,为什么地球上不应该问作业问题? – SingerOfTheFall 2013-02-11 07:25:49
@SingerOfTheFall我认为他们被禁止? – 2013-02-11 07:36:11
@Alex,不,我们只是不再用[tag:作业]标记问题。作业问题与其他任何问题没有区别。你可以在[tag:homework]标签info – SingerOfTheFall 2013-02-11 07:40:02