Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 程序错误地从文本文件中读取信息,看起来是从左到右,然后是从右到左_C++_Fstream - Fatal编程技术网

C++ 程序错误地从文本文件中读取信息,看起来是从左到右,然后是从右到左

C++ 程序错误地从文本文件中读取信息,看起来是从左到右,然后是从右到左,c++,fstream,C++,Fstream,我试图读入关于A.A单词和B.所说单词的频率的信息。当函数读入信息时,第一个调用从左(Word)到右(Frequency)读取信息,然后下一个调用从右(Frequency)到左(Word)。我假设这是由于我的格式。我的假设是它跳过了这个词 dicFile>word>>freq; intfrequ=stoi(freq); newItem.key=word; newItem.wordCount=frequ; 树。AVL_插入(新项); } } 否则{cout那是因为它不能处理“苹果” 首先,whil

我试图读入关于A.A单词和B.所说单词的频率的信息。当函数读入信息时,第一个调用从左(Word)到右(Frequency)读取信息,然后下一个调用从右(Frequency)到左(Word)。我假设这是由于我的格式。我的假设是它跳过了这个词

dicFile>word>>freq;
intfrequ=stoi(freq);
newItem.key=word;
newItem.wordCount=frequ;
树。AVL_插入(新项);
}
}

否则{cout那是因为它不能处理“苹果”

首先,
while(dictionaryFile>>word)
读“Accounting”,然后

dictionaryFile >> word >> freq;
将“3”读入
word
,将“苹果”读入
freq

你应该做的是

while (dictionaryFile >> word >> freq) {
    int frequ = stoi(freq);
    // ...
或者,您可以删除一组变量无序排列,并直接读入“项”:


while(dictionaryFile>>word){dictionaryFile>>word>>freq;
->你读了两遍
word
,然后又读了两遍
freq
。根据你的描述,这不是你想要做的。。。(通过在调试器中逐步执行来检查这一点。查看
word
freq
中在
while
中的第一行之后出现的内容,谢谢你。IMHO,正确的方法是
while(dictionaryFile>>word>>freq){
然后完全删除下一行。(不客气)。;-)您也可以考虑创建<代码> Frq<代码>类型<代码> int <代码>。这将使<代码> STOIE()<代码>过时。
while (dictionaryFile >> newItem.key >> newItem.wordCount) {
    tree.AVL_Insert(newItem);
}