0

Hi, can anyone help me fix my code. This program is linked to a project list (with classes). This is the main program. It has to open up a file of strings and output then in order of how many there are. But its not working though. Can someone help me fix it up.

#include <iostream>
#include <fstream>
#include <string>
#include "IPlist.h"
using namespace std;

int main()
{
    IPlist p;
    string fileName;
    ifstream infile;

    cout << "Enter name of file : " << flush;
    cin >> fileName;
    
    infile.open(fileName.c_str());
    
    if(infile >> IPaddress >> count)
    {
         if(!p.empty())
         {
                 p.display();
         }
    }
    
    if(!infile)
    {
               infile.clear();
               cout << "Invalid file name" << endl;
               
    }
    
   system ("pause");
   return 0;
}

Do I have to use my other class functions first? Like I have:
bool isPresent(string address)
updateCount(string address)
void display()
void insertInOrder(string address)

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

lines 26-31 are in the wrong order. Move them between lines 16 and 18. You have to validate the file is opened before you can read it.

If that still doesn't fix the problem then I suspect the file is not where you think it is. On line 14 use getline() and enter the full or relative path to the file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.