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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:52:52+00:00 2026-06-13T11:52:52+00:00

My program takes in two parameters, first parameter is name to be changed, and

  • 0

My program takes in two parameters, first parameter is name to be changed, and 2nd parameter is the name to which change it.

After execution, my textfile is missing the the second line, which suppose to be changed from May to MayMay. I’m not sure if my if else statement has problems or while(!file.fail) has problems.

This is my original textfile.

user;   pass;   1234; John;     1111
user1;  pass1;  2345; May;      2222
user2;  pass2;  3456; Mary;     3333
user3;  pass3;  4567; Andy;     4444
hr;     hr;     5678; Jonathan; 5555
admin;  admin;  6789; Aili;     6666
user10; pass10; 7890; eggy;     9999
user11; pass11; 9807; Mary;     7777

This is my output textfile after program execute.

user;   pass;   1111;  John;

user2;  pass2;  3333;  Mary;
user3;  pass3;  4444;  Andy;
hr;     hr;     5555;  Jonathan;
admin;  admin;  6666;  Aili;
user10; pass10; 9999;  eggy;
user11; pass11; 7777;  Mary;

        pass11; 7777;  Mary;

This is my code:

bool Employee::changeName(string nnn, string mmm)
{
    int i = 0;
    ifstream file("login1.txt"); // to open the file
    string name, empty, empty2, empty3, empty4; // fusername is use to store the first parameter in textfile,empty is use to store the rest of the line after the ';'
    string store[100]; // initialize a array to store textfile contents

    while (!file.fail()) // loop if file didn't fail
    {   
        getline(file, empty, ';'); // use ; as delimiter
        getline(file, empty2, ';'); // use ; as delimiter
        getline(file, empty3, ';'); // use ; as delimiter
        getline(file, name, ';'); // use ; as delimiter
        getline(file, empty3); // use line end as delimiter, and to skip the rest of the information
        string add = ""; //initialize add string to nothing when it loops

        if(name != nnn) // to check if the username in textfile do not match the user input name
        {
            add += empty + ';' + empty2 + ';' + empty3 + ';' + name + ';' + empty4; // adds back the username and rest of the line together back    
            store[i] = add; // store into an array
            cout << "i is: " << i << endl; // debugging.
            cout << "store array[] = " << store[i] << endl; // debugging..
            i++;
        }
        else if(name == nnn)
        {
            add += empty + ';' + empty2 + ';' + empty3 + ';' + mmm + ';' + empty4; // adds back the name and rest of the line together back 
            store[i];
            cout << "i is: " << i <<endl; // debugging.
            cout << "store array[] = " << store[i] << endl; // debugging..
            i++;
        }
        else{}  
    }

    remove("login1.txt"); //remove the textfile
    ofstream pwd2_file ; // initilize a outputstream textfile
    pwd2_file.open("login1.txt"); // create a new file call login1.txt

    for (int x = 0; x < i; x++)//for loop to store store[] array into login1.txt
    {
        pwd2_file << store[x] << endl; // storing into textfile
    }
    pwd2_file.close(); // close the output stream
}
  • 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-13T11:52:53+00:00Added an answer on June 13, 2026 at 11:52 am

    The problem causing the empty line is that when you replace the name in the else-if statement you have the lines

    add += empty+';'+empty2+';'...
    store[i];
    

    I’m guessing that should be

    store[i] = add;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to make an uninformed search (Breadth-first-Search) program which takes two nodes and
I need to make a program, ioloop.c, which takes two command line parameters that
I'm writing a program, which takes two words as command line arguments, does something
I have a program with two methods. The first method takes two arrays as
I am trying to use a Stored Procedure which takes two parameters (login, pw)
I have a generic class which takes two type parameters, Generic<A, B> . This
I have a program that takes two files as an argument. The first file
My program takes two files with words sorted as parameter and performs the mixture
My program takes in a date time packet from a hardware device, which is
This program takes the first number in a file and indicates how many numbers

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.