Wierd Error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>


using namespace std;

struct domList
{
string domName;
string ipAddress;
int counter;
};

void add(domList list[], ifstream inFile, int len);
    

int main (){
    
    char command;
    
    domList list[NULL];
    int listLength = 0;
    
    string ipNum, domName;
    int counter = 0;

    ifstream dataFile;
    
    //stores the name of the dataFile
    string dataFile1;
    
    cout << "Please enter the data file you wish to use: ";
    cin >> dataFile1;
      
    dataFile.open (dataFile1.c_str());
    if (!dataFile) 
    {
       cout << "bummer file\n\n";
       system ("pause");
       return 1;
    }
    
    while(!dataFile.eof()){
       dataFile >> command;
       switch(command){
                       case 'A':
                                add(list, dataFile, listLength);
                                listLength++;
                       break;
                       default: 
                                cout << "Enter a valid command." << endl;
    }
}
}

void add(domList list[], ifstream inFile, int len)
{
     domList one;
     inFile >> one.domName >> one.ipNum;
     one.counter = 0;
     list[len] = one;
}




After compiling and running i get an error on line 37, 49, 59 and 64.

Any ideas?





Last edited on
Line 37:

The open function does not take a string. It takes a char*
http://cplusplus.com/reference/iostream/ifstream/open/

You're missing a } on line 56

On line 61, the object known as dataFile does not exist.

Last edited on
Deleted.
Last edited on
fixed the previous errors. now I have this even wierder error. It takes me to ios_base.h

738 C:\Dev-Cpp\include\c++\3.4.2\bits\ios_base.h `std::ios_base::ios_base(const std::ios_base&)' is private

769 C:\Dev-Cpp\include\c++\3.4.2\streambuf `std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]' is private


And then the error on line 49 is still there.

I have also fixed the original code for all the original errors.
Last edited on
There is no copy constructor for streams. Pass it by non-const reference
Yay for more errors. Lines 73, 85, and 89 all say that length is undeclared. It's probably something really obvious but I just don't see it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cmath>


using namespace std;

struct domList
{
string domName;
string ipAddress;
int counter;
};

void insertOne(domList list[], ifstream& inFile, int len);
void modify(domList list[], string dName, string IpNum);
void Delete(domList list[], string dName);    

int main (){
    
    char command;
    
    domList list[NULL];
    int listLength = 0;
    
    string ipNum, DomName;
    int counter = 0;

    ifstream dataFile;
    
    //stores the name of the dataFile
    string dataFile1;
    
    cout << "Please enter the data file you wish to use: ";
    cin >> dataFile1;
      
    dataFile.open (dataFile1.c_str());
    if (!dataFile) 
    {
       cout << "bummer file\n\n";
       system ("pause");
       return 1;
    }
    
    while(!dataFile.eof()){
       dataFile >> command >> DomName >> ipNum;
       switch(command){
                       case 'A':
                                insertOne(list, dataFile, listLength);
                                listLength++;
                       break;
                       case 'M':
                                modify(list, DomName, ipNum);
                       break;
                       default: 
                                cout << "Enter a valid command." << endl;
    }
}
}

void insertOne(domList list[], ifstream& inFile, int len)
{
     domList one;
     inFile >> one.domName >> one.ipAddress;
     one.counter = 0;
     list[len] = one;
}

void change(domList list[], string dName, string IpNum)
{
     for(int i = 0; i < list.length(); i++)
     {
          if(list[i].domName == dName)
          {
                list[i].ipAddress = IpNum;
                list[i].counter += 1;
          }
     }
}

void Delete(domList list[], string dName)
{
     for(int i = 0; i < list.length(); i++)
     {
          if(list[i].domName == dName)
          {
               for(int l = i; l < list.length(); l++)
               {
                     list[l] = list[l+1];
               }
          }
     }
}
Topic archived. No new replies allowed.