0
我正在解析用戶的座標,我想將它們添加到一個矢量(不知道將有多少)。但是,插入了錯誤的值。如圖所示:考慮座標,但錯誤的值插入到矢量中?
string userInput;
getline(cin,userInput);
for(int i = 0; i < userInput.length(); i++)
{
if(isdigit(userInput[i]))
{
results.push_back(userInput[i]);
if(isdigit(userInput[i + 1])) //check the value next to it too (max of double digits)
{
results[i] = 10 * (userInput[i + 1]); //add it to the vale
}
}
}
如果我輸入(1,2) - (3,4),在「(」被跳過,但由於某些原因,當它看到的那個1是一個數字,它把49到向量以及其他隨機數字。任何幫助,將不勝感激,謝謝!