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

May 9, 2013 at 5:59pm
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!
}
May 9, 2013 at 6:09pm
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 May 9, 2013 at 6:09pm
May 9, 2013 at 6:11pm
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
May 9, 2013 at 6:15pm
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 May 9, 2013 at 6:17pm
May 9, 2013 at 7:18pm
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"

May 9, 2013 at 7:31pm
maybe try a for loop

1
2
3
4
for(int i = 0; i < 7; ++i) {
     getline(dfile, line);
     fdata[i] = line;
}
May 9, 2013 at 7:41pm
Thanks Carm and SamuelAdams. Both those suggestions fix the issues.
May 9, 2013 at 7:58pm
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 May 9, 2013 at 7:58pm
May 10, 2013 at 5:12am
Thanks giblit. I discovered that when I started to manipulated data. I should have known that.
Topic archived. No new replies allowed.