Click here to Skip to main content
16,015,097 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Toolbar in ActiveX Control Pin
jahfer21-Feb-05 19:29
jahfer21-Feb-05 19:29 
GeneralRe: Toolbar in ActiveX Control Pin
Sheng Jiang 蒋晟22-Feb-05 13:31
Sheng Jiang 蒋晟22-Feb-05 13:31 
GeneralRe: Toolbar in ActiveX Control Pin
Anand for every one7-Mar-05 19:07
Anand for every one7-Mar-05 19:07 
GeneralRe: Toolbar in ActiveX Control Pin
Sheng Jiang 蒋晟10-Mar-05 13:34
Sheng Jiang 蒋晟10-Mar-05 13:34 
Questionhow to create an icon for dll file? Pin
includeh1021-Feb-05 17:46
includeh1021-Feb-05 17:46 
AnswerRe: how to create an icon for dll file? Pin
Blake Miller22-Feb-05 4:56
Blake Miller22-Feb-05 4:56 
GeneralInkvoke web service from C++ through SoapClient Pin
Member 80845921-Feb-05 15:23
Member 80845921-Feb-05 15:23 
Generalreading and outputting data from a binary file... Pin
Moochie521-Feb-05 14:36
Moochie521-Feb-05 14:36 
I am having difficulty reading from a binary file. For some reason, the program is not reading from it properly.

My code is short and so I will show all of it

#include <iostream.h><br />
#include <fstream.h><br />
<br />
struct Info<br />
{<br />
	//unsigned short ID;<br />
	int ID;<br />
	float GPA, FinAid;<br />
<br />
	char state[3];<br />
	char gender[2];<br />
	char Fname[15];<br />
	char Lname[15];<br />
	char status[15];<br />
};<br />
<br />
void main(void)<br />
{<br />
	fstream people;<br />
	Info person;<br />
	char again;<br />
	people.open("C:\\Student.bin", ios::in | ios::binary);<br />
	if(!people)<br />
	{<br />
		cout << "Error Opening File!  Program Aborting!!\n\n";<br />
		return;<br />
	}<br />
	people.read((char *)&person, sizeof(person));<br />
	while (!people.eof())<br />
	{<br />
		cout << "ID: ";<br />
		cout << person.ID << endl; <br />
		cout << "GPA: ";<br />
		cout << person.GPA << endl;<br />
		cout << "Financial Aid: ";<br />
		cout << person.FinAid << endl;<br />
		<br />
		cout <<"State: ";<br />
		cout << person.state << endl;<br />
		cout << "Gender: ";<br />
		cout << person.gender << endl;<br />
		cout << "First Name: ";<br />
		cout << person.Fname << endl;<br />
		cout << "Last Name: ";<br />
		cout << person.Lname << endl;<br />
		cout << "Status: ";<br />
		cout << person.status << endl;<br />
		cin.get(again);<br />
		people.read((char *)&person, sizeof(person));<br />
	}<br />
	people.close();<br />
}<br />



When I debug it, it will not gather the correct data and also show weird characters. I get the feeling that it is trying to read the file in text file mode still. Not sure why as I've checked examples through the internet and I have pretty much the same code.
GeneralRe: reading and outputting data from a binary file... Pin
S. Senthil Kumar21-Feb-05 15:25
S. Senthil Kumar21-Feb-05 15:25 
GeneralRe: reading and outputting data from a binary file... Pin
Moochie521-Feb-05 17:47
Moochie521-Feb-05 17:47 
GeneralRe: reading and outputting data from a binary file... Pin
S. Senthil Kumar21-Feb-05 17:58
S. Senthil Kumar21-Feb-05 17:58 
GeneralRe: reading and outputting data from a binary file... Pin
Cedric Moonen21-Feb-05 20:13
Cedric Moonen21-Feb-05 20:13 
Generalprocesses Pin
mpapeo21-Feb-05 14:06
mpapeo21-Feb-05 14:06 
GeneralRe: processes Pin
Aamir Butt22-Feb-05 0:17
Aamir Butt22-Feb-05 0:17 
GeneralRe: processes Pin
mpapeo28-Feb-05 16:31
mpapeo28-Feb-05 16:31 
GeneralDialog Bars in Dialog Based applications Pin
Will115721-Feb-05 12:49
sussWill115721-Feb-05 12:49 
GeneralRe: Dialog Bars in Dialog Based applications Pin
Will115721-Feb-05 13:13
sussWill115721-Feb-05 13:13 
GeneralRe: Dialog Bars in Dialog Based applications Pin
JohnCz21-Feb-05 13:50
JohnCz21-Feb-05 13:50 
GeneralRe: Dialog Bars in Dialog Based applications Pin
Mohammad Tarik22-Feb-05 1:23
Mohammad Tarik22-Feb-05 1:23 
GeneralProblem With Dll Injection Pin
gamitech21-Feb-05 10:37
gamitech21-Feb-05 10:37 
Generalstart when cd is in Pin
jonavon blakly21-Feb-05 7:40
jonavon blakly21-Feb-05 7:40 
GeneralRe: start when cd is in Pin
Ravi Bhavnani21-Feb-05 7:44
professionalRavi Bhavnani21-Feb-05 7:44 
GeneralSafe Exit Pin
DanYELL21-Feb-05 6:36
DanYELL21-Feb-05 6:36 
GeneralRe: Safe Exit Pin
Michael Dunn21-Feb-05 6:53
sitebuilderMichael Dunn21-Feb-05 6:53 
GeneralStatic map Pin
ralfeus21-Feb-05 4:57
ralfeus21-Feb-05 4:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.