no matching function for call to 'getline??
Jul 11, 2020 at 4:50am UTC
no matching function for call to 'getline(std::ifstream&, std::string [5])'
55 | getline(fin, rndName);
what does this mean?
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
string usersFile; //stores users file name
const int MAX_RNDNAMES = 5; //list size
int nrndNames = 0; //list capcacity
int u;
string rndName[MAX_RNDNAMES]; //name array
string tempVar;
//user introduction
introduction(objective, instructions);
// get user file name
cout <<"Input file name for sorting. " <<endl <<endl;
getline(cin, usersFile);
cout <<endl;
// open input file
ifstream fin; //
fin.open(usersFile.c_str()); //
if (!fin.good()) throw "I/O error" ; //
// getnames
while (true )
{
if (!fin.good()) break ;
getline(fin, rndName);
}
//close input file
fin.close();
// open output file
ofstream fout; //reserve "fout" for use
fout.open ("friends.txt" ); //open specifed file
if (!fout.good()) throw "I/O error" ; //if file isnt open output error to console
//sort
for (int j = 0; j < nrndNames; j++)
{
if (rndName[j] > rndName[j+1])
{
tempVar = rndName[j];
rndName[j] = rndName[j+1];
rndName[j+1] = tempVar;
}
}
//output
for (u = 0; u < nrndNames; u++)
{
cout << rndName[u] <<endl <<endl;
cout << endl;
fout << rndName[u] <<endl <<endl;
fout << endl;
}
//close input file
fout.close();
Jul 11, 2020 at 5:04am UTC
It means you can't do a
getline
for an
array of strings - and that's what you're trying to do right now. It's expecting you to use
getline
for a single string, not the whole array.
1 2 3 4 5 6
while (true )
{
if (!fin.good()) break ;
getline(fin, rndName); // NOT VALID
getline(fin, rndName[i]); // VALID (assuming i is a valid position)
}
Jul 11, 2020 at 5:07am UTC
1 2 3
string name;
while (nrndNames < MAX_RNDNAMES && getline(fin, name))
rndName[nrndNames++] = name;
Jul 11, 2020 at 5:55am UTC
thank you
Topic archived. No new replies allowed.