Results 1 to 4 of 4

Thread: Accessing VB Random files in C++

  1. #1
    barnabas
    Guest
    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

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    How are you reading the file?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    barnabas
    Guest

    reading the file

    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;
    }

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    In C++ you don't need struct logstruct logdata -- just use logstruct logdata

    All I can suggest is try using:
    Code:
    datafile > logdata;
    This will load it BINARY rather than text mode.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width