In: Computer Science
C++
The txt file is not showing up in my output
#include <iostream> #include <fstream> #include <string> #include "Classroom.h" using namespace std; Classroom myLib; void loadDataset(string fileName) { ifstream myFile; myFile.open(fileName.c_str()); } void continueMessage(string message) { cout << message << endl; cout << "Press Enter to continue.." << endl; cin.get(); } int main() { string fileName = "dataset.txt"; loadDataset(fileName); myLib.print(); continueMessage; string ID = "Janet Newman"; myLib.removeStudent (ID); continueMessage("Janet Newman has been removed."); //--------------------------------------------------------------------------- myLib.print(); continueMessage("All students are listed!"); return 0; }
There is a minor mistake, you forget to read data from the file in LoadDataset() function, I commented there so just add code to read the file then it will work nicely,
PLEASE GIVE THUMBS UP, THANKS
CODE:
#include <iostream>
#include <fstream>
#include <string>
#include "Classroom.h"
using namespace std;
Classroom myLib;
void loadDataset(string fileName)
{
ifstream myFile;
myFile.open(fileName.c_str());
//The txt file not showing up in your output because, you
are not reading the data from file, you just opened the input file
in read mode but you are not reading.
//So read your input file into myLib object from file, then only
use myLib object to print.
}
void continueMessage(string message) {
cout << message << endl;
cout << "Press Enter to continue.." << endl;
cin.get();
}
int main()
{
string fileName = "dataset.txt";
loadDataset(fileName);
myLib.print();
continueMessage;
string ID = "Janet Newman";
myLib.removeStudent (ID);
continueMessage("Janet Newman has been removed.");
//---------------------------------------------------------------------------
myLib.print();
continueMessage("All students are listed!");
return 0;
}