2013-03-22 119 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); 

看看它是如何工作爲你。我總是陷入類似的陷阱,通常可以通過清除緩衝區來解決它。