Here is the code I am working with right now, I get some odd output when I type in my file location of some memory location (8128231) which I find odd. I understand I need to add a parameter if the user inputs the wrong file location and will prompt them to do it again, I'll do that later.
I am currently stuck with the while loop where, I want the while loop to read through my text file that has 4 columns with different variable types in the order that is shown below within the while loop:
name gender school score
I know that I can add a string type of some sort like, while(inFile >> lineIn)
and then read the file based off what I have, but I want to do it the way that I'm currently working with that include the eof statement, because I know there's a way to get around the white space so that the file outputs what needs to be shown from the file. How can I do this?
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
//declarations
char M, F;
string name, gender, school, fileLocation, lineIn;
int femaleScore, maleScore, ccScore, univScore, ccTotal, univTotal, femaleTotal, maleTotal, score;
//stream variables
ifstream inFile;
ofstream outFile;
//prompt for user for file location
cout << "Enter file and name for the scores " << endl; //C:\Users\ctach\Documents\CS161\Text Downloads
cin >> fileLocation;
//opens the text file
inFile.open(fileLocation);
while (!inFile.eof()) { //reads file until end of file (eof)
inFile >> name >> gender >> school >> score; //reads the .txt file in this order
cout << name << gender << school << score << endl; //outputs the .txt file in this order
if (gender == "M") {
}
}
cout << "Press any key to continue..." << endl;
cin.ignore();
cin.get();
return 0;