I need to get only specific characters from a text file. I am using the getline()
function in C++. my compiler keeps giving me the error that there is no matching member function call for getline()
, how can I fix that?
I'm trying to pull last names and scores from the file.
the file looks like:
Weems 50 60
Dale 51 60
Richards 57 60
...
Here's the code I'm trying:
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
int main ()
{
//input variables
float GradeScore;
float TotalPoints;
float GradePercent;
string LastName;
ifstream myFile;
//open file
myFile.open ("/Users/ravenlawrence/Documents/TestGrades.rtf",ios::in);
// if file is open
if (myFile.is_open()) {
while(!myFile.eof()) {
string data;
getline(myFile,data); //reading data on line
myFile.getline(LastName, ' ');//storing data in LastName
myFile.getLine(GradeScore,' ');//storing data in GradeScore
myFile.getLine(TotalPoints,' ');//storing data in Total Points
cout << LastName << endl;
// cout<<data<<endl; //print it out
}
}
return 0;
}