2017-09-02 99 views
1

我有一個我正在爲學校工作的程序。代碼在學校服務器上按照預期編譯和運行,但檢查的程序輸出的東西超過了我想要的。在對象之前打印C++無意義對象

正確的輸出在左邊,我的是在右邊。箭頭顯示不同的問題線。

        > : 1, 5:06 
            >   : 1, 5:06 
            >     2. : 5:06 
Mayfield, Curtis: 1, 5:06     Mayfield, Curtis: 1, 5:06 
     Superfly: 1, 5:06       Superfly: 1, 5:06 
       2. Pusherman: 5:06        2. Pusherman: 5:06 

這是程序如何運行提供的文本文件之一。正如你所看到的,這裏沒有問題。

King Crimson: 2, 21:29 
     Larks' Tongues In Aspic: 3, 15:33 
       2. Book of Saturday: 2:49 
       3. Exiles: 5:47 
       6. Larks' Tongues In Aspic, Part 2: 6:57 
     Three of a Perfect Pair: 1, 5:56 
       9. Larks' Tongues In Aspic, Part III: 5:56 
Larkins, Ellis: 1, 2:44 
     Jazz Piano III (A Smithsonian Collection): 1, 2:44 
       2. Between the Devil and the Deep Blue Sea: 2:44 
League of Crafty Guitarists: 1, 2:37 
     Intergalactic Boogie Express: 1, 2:37 
       3. Larks' Thrak: 2:37 
Lewin, Michael: 1, 5:25 
     A Russian Piano Recital: 1, 5:25 
       2. Balakirev, The Lark: 5:25 
Paderewski, Ignace: 2, 6:00 
     Josef Hofmann & Ignace Jan Paderewski Play Liszt: 1, 3:03 
       5. Schubert-Liszt, Hark, Hark, The Lark: 3:03 
     Paderewski Plays Concert No. 1: 1, 2:57 
       7. Schubert-Liszt, Hark, Hark the Lark: 2:57 

我知道這是很難不知道檢查器如何工作,但我也不知道任何事情。任何想法爲什麼會發生?

+2

看起來更像是你沒有正確讀取數據。 –

+3

你在'lib'中顯然比你想象的要多。特別是,你有空字符串作爲鍵的條目。找出原因;問題在於你沒有顯示的代碼。 –

+1

我預測你在使用'while(!eof())...'反模式時會遇到一個問題:https://stackoverflow.com/a/5605159/12711 –

回答

0

邁克爾伯爾是正確的。我正在使用while(!file.eof)循環,但我切換到while(file.is_open())並使用兩個if(file.eof())退出。

+0

您可能已經解決了遇到的問題,但解決方案仍然聽起來很腥。您可能想要在http://codereview.stackexchange.com上發帖 –