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 8981407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:19:41+00:00 2026-06-15T20:19:41+00:00

I have a problem with the following section. This particular part should do the

  • 0

I have a problem with the following section.
This particular part should do the following:
List all modules taught by selected lecturer

I’m struggling with part of match the input from the user with data in the text file, and only display that list of module taught by the selected lecturer.

I have text file called: Taught.txt and the content of the text file is of the following:

IS1S01  AW 
IS1S02  MG 
SE2S552 BM 
CS2S504 BM 
CS3S08  SL 
MS3S28  DJ
CS1S03  EM 
BE1S01  SJ 
BE2S01  SH 
SS1S02  AB 
SE1S02  AW

The below section is code I have done so far.

void listofmodulebylecturer()
{
    std::string Lecturer;
    std::string Module;

    // Display message asking for the user input
    std::cout << "\nList all modules taught by selected lecturers." << std::endl;
    std::cout << "Enter your preferred lecturers." << std::endl;

    // Read in from the user input
    std::cin >> Lecturer;

    // Read from text file and Display list of modules taught by the selected lecturer

    std::ifstream infile;

    // infile.open("Lecturer");
    infile.open("Taught.txt");

    if (!infile)
    {
        std::cout << "List is empty" << std::endl;
    }
    else
    {
        std::cout << "\nList of Modules:" << std::endl;

        while(!infile.eof())
        {
            getline(infile,Module);

            std::cout << Module << std::endl;
        }

        std::cout << "End of list\n" << std::endl;
    }

    infile.close();         // close the text file  
    system ("PAUSE");
}

I was thinking of using

if (........)
{
}
else

I wondering if that can work?

  • 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-06-15T20:19:43+00:00Added an answer on June 15, 2026 at 8:19 pm

    Using infile.eof() cannot work reliable for the purpose you want to use it for. You should read two words and print the first word if the second word matches the expected. Reading the words would look something like this:

    for (std::string module, teacher; infile >> module >> teacher; ) {
        // check if the teacher is the correct one and, if so, print the module
    }
    

    … and, yes, an if statement works for this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: In my master report in the detail section i
I have a problem with following script. It generates a list of places which
Never thought I'd have this problem :) The following snippet of code works in
I have the following problem: I have to list several items each with several
I am facing this strange problem with the following section of code <% if
I have the following problem trying to use a custom config section in my
I have a problem following from my previous problem . I also have the
I have following problem: I have to make a ASP.NET Webapplication with a two-row
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening

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.