Error in my code

I keep getting the error message: C2065 Line 49 'ID':undeclared identifier



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
#include <iostream>
#include <fstream>
#include <string>
#include "Classroom.h"


using namespace std;

Classroom myLib;


//Read the dataset file and loads myLib list
void loadDataset(string fileName) {
	ifstream inFile;
	inFile.open(fileName.c_str());

}

//Just for convenience...
void continueMessage(string message) {
	cout << message << endl;
	cout << "Press Enter to continue.." << endl; cin.get();
}

int main() {	
	
	string fileName = "dataset.txt";
	loadDataset(fileName);

	continueMessage("Dataset file is loaded to the program!");


	myLib.print();
	continueMessage("All students are listed!");


	myLib.removeStudent (ID);
	continueMessage("Janet Newman has been removed.");
	
Last edited on
Something’s probably out of scope or not declared properly from the error
It looks like another case of writing 100's of lines of code, and then wondering why it doesn't work.

You're missing an ID, so make one.
1
2
3
        string ID = "Janet Newman";
	myLib.removeStudent (ID);
	continueMessage("Janet Newman has been removed.");


And what's this?
1
2
3
	string title = line.substr(0, ind1);
		string author = line.substr(ind1 + 1, ind2 - ind1 - 1);
		string ISBN = line.substr(ind2 + 1);

Title, author and ISBN are not mentioned anywhere else in your code.

It's all student ID, student name and their major.

Further, you read the file, but do nothing with the results of your efforts.



Main line 49: Where is ID defined? You can't pass a variable that's not in scope.
ID is a member of Student, but you're not referencing a Student instance.
You probably want to ask the user which student to remove, put the answer in a local variable and then pass that local variable to removeStudent().

main lines-23-25: These variables go out of scope for each iteration of the loop. What's the point?

Topic archived. No new replies allowed.