L
lurkerboy
I'm trying to open a file to read some stock market data in the
metastock format. I can't figure out how to get it to read the
correct bytes into the struct that I have defined in accordance to the
Metastock data format.
Can someone help a rookie out?
lurkerboy
#include "stdafx.h"
#include "stdlib.h"
#include <Fstream.h>
#include <fcntl.h>
#include <io.h>
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned long u_long;
struct rec_1 {
u_short num_files; /* number of files master contains */
u_short file_num; /* next file number to use (highest F#
used) */
char zeroes[49];
};
int main(int argc, char* argv[])
{
struct rec_1 record1;
//open the file
ifstream myfile("C:\sf\data.txt", ios::in | ios::binary |
ios::nocreate);
if(! myfile)
{
cerr << "Failed to open file.\n";
exit(EXIT_FAILURE);
}
//start reading data
//1st record from Master
cout<<"\nThe size of record1 in bytes is "<< sizeof(record1);
myfile.read((char*) &record1,sizeof(record1));
//here is the problem I need to read properly from the file
first
cout<<"\nThe number of files in Master is "<<
record1.num_files;
cout<<"\nThe next file number to use in Master is "<<
record1.file_num;
cout<<"\nThe rest of record 1 is {{" << record1.zeroes
<<"}}\n";
//close file
myfile.close();
//exit
return 0;
}
metastock format. I can't figure out how to get it to read the
correct bytes into the struct that I have defined in accordance to the
Metastock data format.
Can someone help a rookie out?
lurkerboy
#include "stdafx.h"
#include "stdlib.h"
#include <Fstream.h>
#include <fcntl.h>
#include <io.h>
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned long u_long;
struct rec_1 {
u_short num_files; /* number of files master contains */
u_short file_num; /* next file number to use (highest F#
used) */
char zeroes[49];
};
int main(int argc, char* argv[])
{
struct rec_1 record1;
//open the file
ifstream myfile("C:\sf\data.txt", ios::in | ios::binary |
ios::nocreate);
if(! myfile)
{
cerr << "Failed to open file.\n";
exit(EXIT_FAILURE);
}
//start reading data
//1st record from Master
cout<<"\nThe size of record1 in bytes is "<< sizeof(record1);
myfile.read((char*) &record1,sizeof(record1));
//here is the problem I need to read properly from the file
first
cout<<"\nThe number of files in Master is "<<
record1.num_files;
cout<<"\nThe next file number to use in Master is "<<
record1.file_num;
cout<<"\nThe rest of record 1 is {{" << record1.zeroes
<<"}}\n";
//close file
myfile.close();
//exit
return 0;
}