Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7082185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:00:54+00:00 2026-05-28T07:00:54+00:00

I have a problem with C/C++. Below is actually my codes. Once the menu

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:00:55+00:00Added an answer on May 28, 2026 at 7:00 am

    After first loop stdin is now the file “file.txt” due to:

    freopen("file.txt","r",stdin);
    

    So you cannot enter anything from the command prompt.

    If you need to read from “file.txt” use a ifstream:

    std::ifstream in("file.txt");
    if (in.is_open())
    {
        while (std::getline(in, Lines))
        {
            // ...
        }
        in.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Solution to original problem (below) may have been discovered. I commented out <identity> ...
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
I have a problem with the SQL statement detailed below. The query returns the
I have a problem for querying records into mysql explanation below The user could
I have a problem when trying to execute this update statement (below) using C#
I have a problem with a template and pointers ( I think ). Below
I have some problem with my cfml website. I have used the below code
I have the same problem as described in the posts listed below. That is,
I have a little demonstration below of a peculiar problem. using System; using System.Windows.Forms;
Problem solved, see below Question I'm working in Flex Builder 3 and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.