Getline [Error] no matching function for call to 'std::basic_istream<char>...

I am trying to write a program where it reads two lines from a text file an combines them to make a password key. My issue is that I keep getting errors when compiling the program. All my research online has come up blank. Can someone tell me what I am missing.

The error I am getting is [Error] no matching function for call to 'std::basic_istream<char>::getline(std::istream&, <unresolved overloaded function type>)'

And the error is for the getline lines. Help!

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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>


using namespace std;

string GetPasswordFromFile(string Asset_Num, string apath)
{
	//Retrieve the Passkey fromt the file.
	
	ifstream dfile;
	dfile.open (apath.c_str());
	
	string fdata[7];
	string pkey;
	cout << fdata[1] << " " << fdata[2];
	 
	dfile >> std::cin.getline (std::cin,fdata[1])
		>> std::cin.getline (std::cin,fdata[2])
		>> std::cin.getline (std::cin,fdata[3])
		>> std::cin.getline (std::cin,fdata[4])
		>> std::cin.getline (std::cin,fdata[5])
		>> std::cin.getline (std::cin,fdata[6])
		>> std::cin.getline (std::cin,fdata[7]);
	
	cout << fdata[2] << fdata[3];
	system("PAUSE");
	std::cout << "Retrieving the password key for " + Asset_Num + ".\n";	
	//dfile.open();
	/*
	if (dfile.is_open())
	{
		cout << "FILE IS OPEN!";
	}
	*/
	//getline (apath, fdata[1]);
	return pkey; //This must change to return the passkey once retrieved!
}
The problem is between lines 20-26, comment them out and the error goes away.

Rewrite that or Try:
 
	dfile >> fdata[1] >> fdata[2] >> fdata[3] >> fdata[4] >> fdata[5] >> fdata[6] >> fdata[7] ;
Last edited on
when you use cin.getline() function, then its parameters would be either a constant character pointer or a character array name and the numbers of characters to get.
i.e.
1
2
3
const int SIZE=20;
char name[SIZE];
cin.getline(name, 15);

http://cplusplus.com/reference/istream/istream/getline/?kw=cin.getline
you can also use getline like this
std::getline(std::cin, STRINGNAMEHERE);
And why do you have using namespace std;
if you are using std on each thing manually honestly I think you should just get rid of the using namespace std.
(btw cout is part of the std namespace also not just cin same with strings and ifstream and ofstream)
Last edited on
SamuelAdams:

The line you suggested fixed all the compiler errors, but when I run the program it crashes on that line every time.

"Process exited with return value 3221225477"

maybe try a for loop

1
2
3
4
for(int i = 0; i < 7; ++i) {
     getline(dfile, line);
     fdata[i] = line;
}
Thanks Carm and SamuelAdams. Both those suggestions fix the issues.
btw tneufeld the reason you had that error was because you went from array positions 1 - 7 instead of 0 - 6 arrays and vectors and stuff like that start at 0 and work their way up thats why carm's solutions works his loop starts at 0 and ends at 6 position 7 does not exist that is why you are getting that weird number.
Last edited on
Thanks giblit. I discovered that when I started to manipulated data. I should have known that.
Topic archived. No new replies allowed.