Reputation: 163
So I am trying to read the text in from file a. The text is in groups of three
Name Country Score( 1 2 3 4 5) which can be any random number and in any order
At this point I am having issues reading in the text into separate arrays
So far I have this
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>
#include <string>
using namespace std;
int main()
{
char* thePlayer[20];
char* theCountry[20];
char* theScore[100];
fstream myInputFile("playerData.txt");
fstream myOutputFile;
// int highestRank = computeHighestRank();
// myInputFile.open("playerData", ios::in);
// myOutputFile.open("playerReport", ios::out);
myInputFile.open("playerData.txt"); //, ios::in);
int theCount = 1;
int i = 0;
int j = 0;
int k = 0;
while (! myInputFile.eof()) {
myInputFile.getline << (thePlayer[i], theCount, '\n');
theCount++;
myInputFile.getline << (theCountry[j], theCount, '\n');
theCount++;
myInputFile.getline << (theScore[k], theCount, '\n');
theCount + 2;
cout << thePlayer[i] << endl;
cout << theCountry[j] << endl;
cout << theScore[k] << endl;
}
myOutputFile << " 1 2 3 4 5 6" << "\n\n" << "123456789012345678901234567890123456789012345678901234567890" << "\n\n" << "Player Country Highest Rank " << "\n\n" << "------------------------------------------------------------" << "\n\n";
int computeHighestRank()
{
}
Which gives me this error. Any ideas would be appreciate it.
Error 1 error C3867:
'std::basic_istream<_Elem,_Traits>::getline'
: function call missing argument list; use'&std::basic_istream<_Elem,_Traits>::getline'
to create a pointer to memberc:\users\justin\desktop\lab 7\lab 7\lab7source.cpp
71
Upvotes: 1
Views: 149
Reputation: 696
Read about getline function here http://www.cplusplus.com/reference/istream/istream/getline/
You have an array of character pointers but space is not allocated for storing the strings themselves. Even if you manage to compile your code, you will end up in crashing your application. You will be better off using string class.
Also you are not incrementing i,j,k which will overwrite the same locations. The second argument in getline is supposed to be the max size to read from input stream so instead of theCount it should be a bigger number.
Upvotes: 0
Reputation: 89
Well, basically it's right there in th e error message; getline is a function, not a stream object. Thus replace
myInputFile.getline << (thePlayer[i], theCount, '\n');
with
myInputFile.getline(thePlayer[i], theCount, '\n');
and you should be one step closer. But what you really want to do is probably more like letting thePlayer, theCountry and theScore be of type std::string and
myInputFile >> thePlayer >> theCountry >> theScore;
Upvotes: 1
Reputation: 13930
That one's pretty self explanatory when you read it. You have no argument list, getline(args), for getline.
Also, please get used to searching for errors like C3867 yourself, it will actually save you some time as there are generally exhaustive examples of every possible cause for them.
Upvotes: 3