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);
}
I have installed all their components from store.rg-adguard.net.
I encountered an unusual issue with Microsoft Edge that I installed manually. When I disable “Shadows under windows” in the Windows performance settings, the menus in Edge display sharp corners instead of rounded ones.
I don't think the problem is related to a debloated version of Windows, as I experienced the same issue on a standard Windows machine in the past.
"AI has just arrived, how is it possible they're already losing jobs?” Huang said."
Hey idiot. It's called these stupid companies spending too much on your AI ###### and having to layoff employees to cover the cost.
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