Undeclared Variable Error?? Thought it's pre-built in <cstdlib>??

Having a hard time figuring out where my error is. It's telling me there are numerous semantic issues which are all pointing to my global variable _MAX_FNAME. I don't understand this because I've included cstdlib from which the variable is defined in.

Environment: XCODE4.6.1

Here are the errors it is displaying:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Week_7 Group
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/myfile.h
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/myfile.h:9:24: Use of undeclared identifier '_MAX_FNAME'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/myfile.h:11:22: Use of undeclared identifier '_MAX_FNAME'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/myfile.h:13:17: Use of undeclared identifier 'newFile'; did you mean 'newfile'?
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/myfile.h:13:25: Use of undeclared identifier '_MAX_FNAME'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/main.cpp
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/main.cpp:24:22: Use of undeclared identifier '_MAX_FNAME'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/main.cpp:25:22: Use of undeclared identifier '_MAX_FNAME'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/main.cpp:26:22: Use of undeclared identifier '_MAX_FNAME'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/main.cpp:47:13: Implicit conversion loses integer precision: 'streamoff' (aka 'long long') to 'int'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/main.cpp:56:13: Implicit conversion loses integer precision: 'streamoff' (aka 'long long') to 'int'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/main.cpp:63:13: Implicit conversion loses integer precision: 'streamoff' (aka 'long long') to 'int'
/Users/shaneyost/Desktop/NEST/XCODE FILES/Week_7/Week_7/main.cpp:69:13: Implicit conversion loses integer precision: 'streamoff' (aka 'long long') to 'int'



Here is my code in main.cpp:
Errors exist on lines 24,25,26 saying undeclared iden. variable _MAX_FNAME
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

// main.cpp
// Week_7


#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

#include "person.h"
#include "myfile.h"

int addStudent();

int main(int argc, char *argv[])
{
    char *file1, *file2, *file3;
    string outStr, buf;
    int length = 0, where = 0, addStud = 0;
    ifstream input;
    ofstream output, outfile;
    file1 = new char[_MAX_FNAME];
    file2 = new char[_MAX_FNAME];
    file3 = new char[_MAX_FNAME];
    filePrompt(file1, file2, file3);
    
    input.open(file1);
    if(!input.is_open()){
        cerr << "Error opening input file " << file1 << " . . .\n";
        system("pause");
        exit(1);
    }
    output.open(file2);
    if(!output.is_open()){
        cerr << "Error opening input file " << file2 << " . . .\n";
        system("pause");
        exit(1);
    }
    outfile.open(file3);
    if(!outfile.is_open()){
        cerr << "Error opening input file " << file3 << " . . .\n";
        system("pause");
        exit(1);
    }
    where = input.tellg();
    cout << "\nThe file pointer is "<< where << " here\n";
    while(getline(input, buf)){
        output << buf << "\n";
    }
    output.close();
    
    input.clear();
    input.seekg(0,ios::beg);
    where = input.tellg();
    cout << "\nThe file pointer is "<< where << " here\n";
    
    while(getline(input,buf)){
        outStr += buf + "\n"; length++;
    }
    cout << outStr;
    where = input.tellg();
    cout << "\nThe file pointer is "<< where << " here\n";
    cout << "\nThe file length is " << length << endl;
    
    input.clear();
    input.seekg(0,ios::beg);
    where = input.tellg();
    cout << "\nThe file pointer is "<< where << " here\n";
    system("pause");
    Person *SRD = new Person[length];
    
    for(int i = 0; i < length; i++){
        getline(input,SRD[i].lastname,',');
        getline(input,SRD[i].firstname,',');
        input >> SRD[i].gender; input.ignore(1);
        getline(input,SRD[i].STUD.major,',');
        input >> SRD[i].STUD.gpa; input.ignore(1);
    }
    for(int i = 0; i < length; i++){
        cout << SRD[i].firstname << " " << SRD[i].lastname << endl;
        if(SRD[i].gender)
            cout << "Gender: Female\n";
        else
            cout << "Gender: Male\n";
        cout << "Major: " << SRD[i].STUD.major << endl
        << "GPA: " << SRD[i].STUD.gpa << endl << endl;
    }
    input.close();
    system("pause");
    char value = ' ';
    addStud = addStudent();
    Person *temp = new Person[addStud];
    cin.ignore(1);
    for(int i = 0; i < addStud; i++){
        system("cls");
        cout << "Enter Student's Last Name: ";
        getline(cin,temp[i].lastname,'\n');
        cout << "Enter Student's First Name: ";
        getline(cin,temp[i].firstname,'\n');
        cout << "Enter Student's Gender M or F: ";
        cin >> value; cin.ignore(1);
        value = toupper(value);
        temp[i].gender = (value == 'F')? true: false;
        cout << "Enter Student's Major: ";
        getline(cin,temp[i].STUD.major,'\n');
        cout << "Enter Student's GPA: ";
        cin >> temp[i].STUD.gpa; cin.ignore(1);
    }
    Person *temp2 = new Person[length+addStud];
    for(int j = 0; j < length; j++){
        temp2[j].lastname = SRD[j].lastname;
        temp2[j].firstname = SRD[j].firstname;
        temp2[j].gender = SRD[j].gender;
        temp2[j].STUD.major = SRD[j].STUD.major;
        temp2[j].STUD.gpa = SRD[j].STUD.gpa;
    }
    for(int j = 0, k = length; k < length+addStud; k++, j++){
        temp2[k].lastname = temp[j].lastname;
        temp2[k].firstname = temp[j].firstname;
        temp2[k].gender = temp[j].gender;
        temp2[k].STUD.major = temp[j].STUD.major;
        temp2[k].STUD.gpa = temp[j].STUD.gpa;
    }
    system("cls");
    for(int i = 0; i < length+addStud; i++){
        outfile << temp2[i].lastname << ','
        << temp2[i].firstname << ','
        << temp2[i].gender << ','
        << temp2[i].STUD.major << ','
        << temp2[i].STUD.gpa << endl;
        if((i+1)< 10)
            cout << " " << i+1 << " " << temp2[i].lastname << ','
            << temp2[i].firstname << ','
            << temp2[i].gender << ','
            << temp2[i].STUD.major << ','
            << temp2[i].STUD.gpa << endl;
        else
            cout << i+1 << " " << temp2[i].lastname << ','
            << temp2[i].firstname << ','
            << temp2[i].gender << ','
            << temp2[i].STUD.major << ','
            << temp2[i].STUD.gpa << endl;
    }
    outfile.close();
    system("PAUSE");
    return EXIT_SUCCESS;
} // end of main
// function definitions
int addStudent(){
    system("cls");
    int value = 0;
    cout << "How many students would you like to add? ";
    cin >> value;
    return value;
}


Here is my code in my two .h files:


Errors exist on 9, 11, 13 saying use of undeclared iden. _MAX_FNAME
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//  myfile.h
//  Week_7
#ifndef MYFILE_H
#define MYFILE_H
#include <iostream>
using namespace std;
void filePrompt(char *master, char *copy, char *newfile){
    cout << "Enter the MasterFile filename: ";
    cin.getline(master,_MAX_FNAME,'\n');
    cout << "Enter the CopyTo filename: ";
    cin.getline(copy,_MAX_FNAME,'\n');
    cout << "Enter the NewMasterFile filename: ";
    cin.getline(newFile,_MAX_FNAME,'\n');
}
#endif





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//  person.h
//  Week_7
#ifndef PERSON_H
#define PERSON_H
using namespace std;
struct Person{
    string lastname;
    string firstname;
    bool gender;
    struct Student{
        string major;
        float gpa;
    }STUD;
};
#endif 


I went ahead and defined this....
#define _MAX_FNAME 256

However now I cannot even open the file I'm wanting to which is a txt file. I made sure the file was in my project folder with all the other files main.cpp and both .h files. However it cannot open it. Any ideas on how I could approach troubleshooting this.

Last edited on
Topic archived. No new replies allowed.