class password
{
private
string password;
public:
void input();
}
void password::input()
{
cout<<" Enter your string :";
getline(cin,password);
}
void main()
{
getline(cin,password);// taking inout first time
cin >> ch;// switch case input
switch (ch)
{
case 1:
p.input(); // taking inout second time
break;
case 2:
// everything works fine in case 2
default:cout << "\n ... ";
}
}
As you can see above the code where I made a class called password with a member function input which when called takes input from user(string inputs).
Now there is no problem in compilation of the code, the problem is when I take input from the user . For first time it takes input properly but as soon as user inputs 1 for switch case as i have commented up there line of control comes in switch and if user tries to enter a string it takes one single word instead of whole string saying progran finished
P.s I have not written the whole program right here
Also, getline function works properly when i take first input but something gets messy inside the switch case for (ch=1)
Please provide me with some solution for this which would solve this problem.