Beginner probs with fstream

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

John Harrison

lurkerboy said:
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?

No-one can help unless you explain what is in the file, and what the correct
bytes are, and what you get instead when you run this program. Try and put
yourself in the position of some-one trying to help, we don't know what is
supposed to happen when you run this program. Neither to we know what you
see when you do run this program. This makes is very hard to help.

Post again but explain yourself better.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top