0

I'm writing a program for my homework that counts words and lines. I'm wondering why i get the error: "no instance of overloaded function "getline" matches the argument list. Argument types are (std::ifstream, int)" I was certain "infile" was of std::ifstream argument type. Could the problem be visual studio or am i quick to blame something without prior knowledge? P.S i searched a bit but would not find a thread with exactly the same problem.. there are similar ones but they end up being that someone put a string of the file name and not the stream itself. Also keep in mind i'm in the middle of writing this i didn't finish yet.

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;



int main()
{

ifstream infile;
infile.open("Lear.txt");
string word;
int countWords = 0, countLines = 0;
while (!infile.eof())
{
    infile >> word;
    countWords++;
    getline(infile, countLines); //issue area here at infile
    countLines++;

}
cout << "Words: " << setw(9) << countWords << endl;
cout << "Lines: " << setw(9) << countLines << endl;
infile.close();

}
newJoe
  • 1
  • 1

1 Answers1

1

There is no std::getline overload that takes an int second parameter. I assume you meant to pass your std::string variable instead.

getline(infile, word);

You should remove the infile >> word; line or decide whether you want to use it or std::getline. I don't think you want both in this case.

This will fix the compiler error but not your program logic. If you use std::getline you'll have to parse each line to count words.

Blastfurnace
  • 17,441
  • 40
  • 50
  • 66
  • Then i believe this has been solved. It seems to have been an error on my part after all. Thanks for the advice and sorry to have wasted any time. – newJoe Sep 25 '15 at 15:00