I have a problem with C/C++.
Below is actually my codes.
Once the menu is hit by an Option 1.
It runs and displays the results as per normal, re-displays the menu as well without fail.
However I will not be able to type anything afterwards.
Why is that so?
Thanks in advance to those who help, cheers!
EDITTED, THIS IS MY WHOLE MAIN
int main()
{
int Option;
Menu m;
do
{
m.showMenu();
cout<<"Please enter your choice:";
cin>>Option;
if (Option == 1)
{
int scenario = 0;
string Lines;
Mobile mobileObj;
freopen("file.txt","r",stdin);
while(true)
{
getline(cin,Lines);
while(Lines.length() > 1 && Lines[0] == ' ') Lines = Lines.substr(1);
if(Lines.length() == 1 && Lines[0] == ' ') continue;
if(scenario == 0)
{
if(Lines == "Mobile Phones & Accessories Classifieds")
{
scenario = 1;
getline(cin,Lines);
continue;
}
}
else if(scenario == 1)
{
if(Lines[0] == '*') continue;
else scenario = 2;
}
else if(scenario == 2)
{
if(Lines[0] == '[')
{
for(unsigned int i=0;i<Lines.length();++i)
{
if(Lines[i] == ']')
{
mobileObj.mobDevName = Lines.substr(i+1);
break;
}
}
}
else if(Lines.length() > 11 && is_number(Lines[0]) && is_number(Lines[1]) && is_number(Lines[10]))
{
mobileObj.dateOfPub = Lines.substr(0,11);
}
else if(Lines.length() >= 5 && Lines[0] == 'S' && Lines[1] == '$')
{
mobileObj.price = Lines;
v_Mob.push_back(mobileObj);
}
else if(Lines == "Browse Marketplace Listings") break;
}
}
cout<<("[Mobile device Name] – [Date of publish] – [Mobile phones’ pricings]\n");
for(unsigned int i=0;i<v_Mob.size();++i)
{
cout << i+1 << ") ";
v_Mob[i].print();
}
cout<<"\n";
cout<<"Going back to main menu ...\n";
cout<<"\n";
}
else if (Option == 2)
{
cout<<"hi\n";
}
}while(Option != 0);
return 0;
}
After first loop
stdinis now the file “file.txt” due to:So you cannot enter anything from the command prompt.
If you need to read from “file.txt” use a
ifstream: