我的程序是假設輸出第一中學姓工作而忽略了,那就是在輸入。但在我的程序中,逗號仍然在我的輸出中,所以顯然我錯過了一些東西。cin.ignore()沒有在程序
#include <iostream>
#include <string>
using namespace std;
char chr;
int main()
{
string last, first, middle;
cout<< "Enter in this format your Last name comma First name Middle name."<<endl; //Input full name in required format
cin>>last; //receiving the input Last name
cin>>first; //receiving the input First name
cin>>middle; //receiving the input Middle name
cout<<first<<" "<<middle<< " " <<last; //Displaying the inputed information in the format First Middle Last name
cin.ignore(','); //ignoring the , that is not neccesary for the new format
cin>>chr;
return 0;
}
您接受CIN的名字,你忽略了逗號前? –
還我不認爲你想cin.ignore –
你能解釋一下你期待這個做什麼?看起來你的'cin.ignore(',')'在錯誤的地方[並且有錯誤的參數]。 –