2013-10-25 2 views
0

안녕하세요, 변수를 유지하는 방법을 lastWordLoaded이라고 말하면서 word이 될 사전에로드되는 다음 단어와 비교해보십시오.변수를 비교하는 데 사용하려면 어떻게해야합니까?

lastWordLoaded> CurrentWord 인 경우 -1을 인쇄하는 방법 compareWords이 있습니다. 따라서 lastWordLoaded> CurrentWord 인 경우 알파벳순이 아님을 의미합니다. lastWordLoaded 인 경우 < CurrentWord는 0을 출력하므로 0 인 경우 파일이 알파벳순입니다. 이 상황에서 lastWordLoaded을 어떻게 사용할 수 있는지 확신 할 수는 없지만.

Dictionary::Dictionary() { 
    //check if the file was opened 
    if (dictionaryFile.is_open()) { 
     while (getline(dictionaryFile, word) && 
      getline(dictionaryFile, definition) && 
      getline(dictionaryFile, type) && 
      getline(dictionaryFile, blank)) { 

        myWords[wordCount] = fromRecord(word, definition, type); 
        if (compareWords(word, lastWordLoaded) != 0) 
        { 
         cout << "\nThe dictionary isnt in alphabetical order." << endl; 
         cout << "Error at word = " << getWordCount() << endl; 
         system("Pause"); 
        } 
     } 
     //close the file 
     dictionaryFile.close();  
} 
+0

이 왜 우리에게 쉽게하지 않는다 코드의 일부? – HAL

+0

, 죄송합니다. – user2881555

+1

왜 "else lastWordLoaded = word;"를 할 수 없습니까? –

답변

0

무엇에 대한 변수에 lastWordLoaded을 유지하고이 같은주기의 끝을 업데이트 : 단지 간결 유지 및 사후,

string lastWordLoaded = ""; 
while (getline(dictionaryFile, word) && 
     getline(dictionaryFile, definition) && 
     getline(dictionaryFile, type) && 
     getline(dictionaryFile, blank)) { 

       myWords[wordCount] = fromRecord(word, definition, type); 
       if (compareWords(word, lastWordLoaded) != 0) 
       { 
        cout << "\nThe dictionary isnt in alphabetical order." << endl; 
        cout << "Error at word = " << getWordCount() << endl; 
        system("pause"); 
       } 
       lastWordLoaded = word; 
    } 
관련 문제