Hello, I am new to this newsgroup. I came here looking for help on an
odd error:
I am currently attempting to make a program that tracks statistics
[manually entered]. It is supposed to write and read objects from a
file.
[ Note: 1.)I got this method from the C++ Black Book by Steven
Holzner (Copyright 2001) ]
Declarations of the ofstream and ifstream objects:
//-------------Code------------------
ofstream pex; // class Player's export stream.
pex.open("database.dat", ios::binary); // Open export stream's
destination
ifstream pin; // class Player's import stream
pin.open("database.dat", ios::binary); // Open import stream's
destination
//-------------End of code section--------------
Active_Player is a Player object. Get_DBNumber() returns an int that
specifies what number the Active_Player is. In the following code, it
(is supposed to) writes the
object to a file.
//-------------Code-------------------
pex.seekp(Active_Player[player_number].Data.Get_DBNumber() *
sizeof(Player), ios::beg);
pex.write(reinterpret_cast<char *> (Active_Player[player_number]),
sizeof(Player));
//-------------End of code section--------------
In the followind code, it (is supposed to) reads the object to a file.
//-------------Code-------------------
pin.seekg(DatabaseSearchNumber * sizeof(Player), ios::beg);
pin.read(reinterpret_cast<char *> (Active_Player[player_number]),
sizeof(Player));
//-------------End of code section--------------
Problem:
error C2440: 'reinterpret_cast' : cannot convert from 'class Player' to
'char *'
I receive this error for both the pin.read() and the pex.write().
When I change it to:
pin.read(reinterpret_cast<Player> (Active_Player[player_number]),
sizeof(Player));
error C2440: 'reinterpret_cast' : cannot convert from 'class Player' to
'class Player'
Upon removing the reinterpret_cast:
pin.read((Active_Player[player_number]), sizeof(Player));
error C2664: 'class istream &__thiscall istream::read(char *,int)' :
cannot convert parameter 1 from 'class Player' to 'char *'
//-----------------------------------------
Any solutions to this problem are welcome. Thanks in advance.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----