Skip to main content
gamedev.net
🔒 Locked

getline() error (c++)

Started by Ekim_Gram 1 reply 350+ views
Original Post
Ekim_Gram
Ekim_Gram
Ok, I''m making an address book. I gotta be quick so I''ll post more of a description later if needed but I''m having an error with the getline() function. Here''s the class function that uses it:
class Address_Book
{
public:
	Address_Book();
	void Add_Address();
	void Edit_Address();
	void Delete_Address();
private:
	vector<DATA> Address_Data;
	vector<char*> Addresses;
	ofstream Write;
	ifstream Read;
	char* Line;
};

Address_Book::Address_Book()
{
	int i = 0;
	Line = "";
	Read.open("Addresses.txt");

	if (Read.fail())
		{
		cout << "Unable to load your address book.\n";
		Read.close();
		}
	
	while(!Read.eof())
		{
		Read.getline(Read, Line); // error here

		Addresses.push_back(Line);
		cout << Addresses[i] << endl;
		i++;
		}
	
	Read.clear();
	Read.close();
}
This is what the error says: C:\Documents and Settings\Michael\Desktop\Projects\Address Book\main.cpp(48) : error C2664: ''class std::basic_istream > &__thiscall std::basic_istream >::getline(char *,int)'' : ca nnot convert parameter 1 from ''class std::basic_ifstream >'' to ''char *'' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Error executing cl.exe. Address Book.exe - 1 error(s), 0 warning(s) I''m using MSVC++ 6.0
R.I.P. Mark Osback Solo Pa Mi Gente VG-Force
MelvinElvin
MelvinElvin
check the declaration of getline. The first parameter is a pointer to a stream of chars, not an input stream.
the call:
Read.getline(Read,Line) ;
would be entirely silly. The first parameter would just be this.
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
daerid
daerid
use std::getline instead of ifstream::getline, and std::string instead of char* :


while(!Read.eof())
{
std::string line;
std::getline(Read,line);
Addresses.push_back(line);
std::cout << Addresses.back() << std::endl;
}
Read.clear();
Read.close();
daerid@gmail.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.