PDA

Click to See Complete Forum and Search --> : Accessing VB Random files in C++


barnabas
Apr 13th, 2001, 06:56 AM
Hello,

I have created a random file in VB. I have tried to access this file using C++ although the file gets read , I am having trouble getting the data in their respective fields. ( data in the first field overflows into the second field and the second field into the next one.)

I have used the following specifications..

IN VB

struct logstruct
cStatus *150
cDate *15
cTime * 15
End struct

dim logdata as logstruct

In C++ I used the following specifications to read the file

struct
{
char cStatus[150];
char cDate[15];
char cTime[15];
};

I am using .dat files

Thank you

Barnabas

parksie
Apr 13th, 2001, 12:01 PM
How are you reading the file?

barnabas
Apr 14th, 2001, 07:10 AM
I have used the following code to read the first record in the file.
please note the file has already been created in a VB application using the Open...For Random statement.

struct
{
char cStatus[150];
char cDate[15];
char cTime[15];
};

int main()
{

struct logstruct logdata;

fstream datafile;
datafile.open("C:\\DLog.dat",ios::in);
datafile>>logdata;

datafile.close;

cout << logdata.cStatus;
cout << logdata.cDate;
cout << logdata.cTime;

return 0;
}

parksie
Apr 14th, 2001, 07:15 AM
In C++ you don't need struct logstruct logdata -- just use logstruct logdata :)

All I can suggest is try using:

datafile > logdata;

This will load it BINARY rather than text mode.