I am slightly confused as to how cin.ignore works. I'll try to make this short. I need to write a program where the user inputs a bunch of data in 1 string, for example : 46728s1000 2750.55John Brown
I need to extract the different parts of that input. I need to extract the first 5 digits, the 's', the 1000, the 2750.55 and John Brown.
int getInformation (bool isFirstInput)
{ int accountNumber;
char accountType;
int minBalance;
double oldBalance;
string firstNamelastName;
const string welcomeMessage = "Welcome to Brandon Lashmet's payroll program\n. Please enter account number, account type, minimum balance, a space, old balance, and first and last name of account owner.";
if (isFirstInput==true)
{
cout<<welcomeMessage;
}
else
{
cout<< "Thank you. Please enter next user's information";
}
cin>> accountNumber;
cin.ignore(5);
cin>> accountType;
cin.ignore(6);
cin>> minBalance;
cin.ignore(11);
cin>> oldBalance;
getline(cin, firstNamelastName);
}
Huh? You're delusional calling the Steam Deck dead. It is so successful that it has sold out multiple times. Even after the price hike this year it sold out again with 24 hours of being back in stock. The demand is real and has not died down even after four years.
Question
blashmet
I am slightly confused as to how cin.ignore works. I'll try to make this short. I need to write a program where the user inputs a bunch of data in 1 string, for example : 46728s1000 2750.55John Brown
I need to extract the different parts of that input. I need to extract the first 5 digits, the 's', the 1000, the 2750.55 and John Brown.
int getInformation (bool isFirstInput) { int accountNumber; char accountType; int minBalance; double oldBalance; string firstNamelastName; const string welcomeMessage = "Welcome to Brandon Lashmet's payroll program\n. Please enter account number, account type, minimum balance, a space, old balance, and first and last name of account owner."; if (isFirstInput==true) { cout<<welcomeMessage; } else { cout<< "Thank you. Please enter next user's information"; } cin>> accountNumber; cin.ignore(5); cin>> accountType; cin.ignore(6); cin>> minBalance; cin.ignore(11); cin>> oldBalance; getline(cin, firstNamelastName); }Does anyone have any idea how this works? Thanks.
Link to comment
https://www.neowin.net/forum/topic/677750-c-cinignore-question/Share on other sites
7 answers to this question
Recommended Posts