2013-03-22 121 views
1

我在使用调试器的代码中遇到问题(Visual C++ & Bloodshed Dev C++),它只是简单地跳过一行代码,或者应该输入的地方。下面的代码:C++调试器在控制台中跳过简单的代码行

for(x = 0; x < TASKLIMIT; ++x) 
{ 
    cout<<"Enter the name of a task: "; 
    getline(cin, task[x].name); 
    cout<<"Enter the priority of the task: "; 
    cin>>task[x].priority; 
    while (task[x].priority > 10 || task[x].priority < 1) 
    { 
     cout<<"Enter a number from 1-10: "; 
     cin>>task[x].priority; 
    } 
    cout<<"Enter the estimated completion time of the task: "; 
    cin>>task[x].completion; 
    cout<<"Enter the deadline of the task: "; 
    cin>>task[x].deadline; 
} 

问题偶尔首先它是在该行

cin>>task[x].deadline; 

然后它移动移动线:

getline(cin, task[x].name); 

时,它得到的第二次迭代for loop

任何帮助将不胜感激

+2

它跳过了哪行代码? – 2013-03-22 01:14:04

+0

最有可能的,这些90%欺骗:http://stackoverflow.com/search?q=+%5Bc%2B%2B%5D+getline+skipping – chris 2013-03-22 01:15:08

+0

我编辑它来显示特定行,对不起 – user2197406 2013-03-22 01:16:18

回答

0

你使用释放模式还是调试模式? 如果您处于发布模式,汇编代码将进行优化。如果您使用该代码进行调试,则始终不会一行一行地移动。

0

尝试更改下面的代码:

cin.ignore(); 
cin.sync(); 

cout<<"Enter the name of a task: "; 
getline(cin, task[x].name); 

看看它是如何工作为你。我总是陷入类似的陷阱,通常可以通过清除缓冲区来解决它。