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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:07:47+00:00 2026-05-24T10:07:47+00:00

It’s me again still working on learning how it is possible for me to

  • 0

It’s me again still working on learning how it is possible for me to manage and manipulate .csv files using c++. I’ve made a small program that creates a new .csv file, fills in the table headings with generic labels, all named “value” for demonstrative purposes.
I then close the file to be sure any changes I made are saved. I then re-open that same file and count the number of lines in the file. I again close the file, and now open a file with references to the values that need to be filled in to the newly created file. I then count the lines of this file and compare them to the number of lines of the newly created file. If the new file has fewer lines than the reference file I need to identify the last line of the new file, add one to that number, and then read the values from that number line in the refrence file to then add the values to that new file.

Now comes to my problems. The program will accurately tell how many lines each file has. Great so far, but when i try to say check if the new file has fewer lines on it in a while loop it is doing something to just keep adding to the numbers of line and in an if staement it only checks once. This is probably a really stupid error like, I should have the whole program in a while loop or something but I do not want the first step of inserting the table headings to be repeated. Any help is appreciated.

I may not be wording myself correctly, If anyone is confused by what I;m saying but think that they can help me solve this issue just ask me to clarify.

#include <iostream>
#include <fstream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    char c;
    int x=0;
    int y=0;
    int loop=1;
    ofstream mynewfile;
    mynewfile.open("MyNewFile.csv");

    if (mynewfile.good())
    {
        mynewfile << "Value,Value,Value,Value,Value,Value," <<endl;
        //End of if mynewfile.good()
    }

    mynewfile.close();

    while(loop==1)
    {
        ifstream mynewfile2;
        mynewfile2.open ("MyNewFile.csv");
        while (mynewfile2.good())
        {
            c = mynewfile2.get();
            if (c=='\n')
                x++;
            //End of while(mynewfile2.good())
        }

        mynewfile2.close();
        ifstream myoldfile;
        myoldfile.open ("MyOldFile.csv");

        while (myoldfile.good())
        {
          c = myoldfile.get();
          if (c=='\n')
              y++;
        }

        myoldfile.close();

        cout << "The Number of lines in the file are " << x << endl;
        cout << "The Number of lines in the file are " << y << endl;

        if(x < y)
        {
          cout << "Keep Going" << endl;
        }
        else if(x = y)
        {
          system("PAUSE");
        }
        else
        {
            loop == 0;
        }
    }

    system("PAUSE");
    return 0;

    //End of main()
}
  • 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-24T10:07:48+00:00Added an answer on May 24, 2026 at 10:07 am

    You made a classic C/C++ error. This line:

    else if(x = y)
    

    assigns the value of y to x. It evaluates to true if y is non-zero. What you meant was this:

    else if(x == y)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

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.