I have wrote a code for taking string from the user in C++. here is the code
#include<iostream>
#include<string>
using namespace std;
string input;
void enterstring()
{
cout<<"\nEnter input: ";
getline(cin,input);
}
void displaystring()
{
cout<<"\nyour string is "<<input<<endl;
}
{
int main()
{
int choice=0;
while(choice!=3)
{
cout<<"Enter choice: "<<;
cin>>choice;
switch(choice)
{
case 1: enterstring();
break;
case 2: displaystring();
break;
case 3: cout<<"\nQuit";
break;
default: cout<<"\ninvalid choice try again";
break;
}
return 0;
}
output of the above code:
Enter choice: 1
Enter input:
Enter choice:
the input section is skipped I don't know why where is the problem. Is the logic wrong, problem with syntax anything. when I call function without using while loop etc it's working fine but in this case it's not working. help me.
cin>>input;in the enterString() functionA program shall contain a global function called main , which is the designated start of the program.--ISO/IEC 14882-2011 3.6.1 p1