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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:06:59+00:00 2026-06-15T15:06:59+00:00

Instruction for program: Read the list of names from names.txt in the format First

  • 0

Instruction for program:
Read the list of names from “names.txt” in the format “First Last”.
Sort the names based upon typical alphabetic order of peoples names based upon last name then first name.
Write the sorted list to a file called “sortednames.txt” in the format “Last, First”.

Here’s my code: file data was stored in fullname array but now I am stuck on how to flip the first and last name in the array??

int main()
{
    const int MAXNAMES = 100;
    int value = 0;
    string fullname[MAXNAMES];

    ifstream inFile;
    inFile.open("names.txt"); //open the file to excess the rainfall data
    if (inFile.fail()) // testing the file
        {
            cout << "Error opening file. Please check that the file currently `enter code here`exist" << endl;
            exit(1);
        }   
    cout << "File successfully open" << endl;
    while(!inFile.eof())
    {
        while(value < 100)
        {
            getline(inFile,fullname[value]);
            value++;
        }
    }

    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-06-15T15:07:01+00:00Added an answer on June 15, 2026 at 3:07 pm

    To flip the name around you could do the following:

    string myString;
    int spacePosition;
    
    value = 0;
    while(value < 100) {
       myString = fullname[value];
       spacePosition = myString.find(" ");
       fullname[value] = myString.substr(spacePostion) + " " + myString.substr(0, spacePostion -1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am writing a simple c program and my requirement is to print RIP(Instruction
I'm working on a graphics transformation program, setting up a listbox to read in
Now I'm making a little program in Java which must read a really big
Instructions: Write a program that will read a line of text that ends with
I am writing a compiler program to read a text file. Some of the
i need to write a program in which main() would read a file(containing some
I am trying to read from a database file (performing a simple select all
I have a program which crashes on the ShellExecute() instruction. If I use the
I'm looking to write a very simple program that can read through an EPS
I have written a dangerous program in C++ that jumps back and forth from

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.