2017-09-02 54 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上发帖 –