473,508 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Beginner probs with fstream

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;
}
Jul 19 '05 #1
1 2095

"lurkerboy" <lu*******@yahoo.com> wrote in message
news:qq********************************@4ax.com...
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
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3203
by: David Briggs | last post by:
I am using MS VC++ 6.0 with MFC I have a simple class: #include <fstream.h> class Data { public: CString WriteStr(); Data();
2
1219
by: Gaz | last post by:
> Hi all > > I am trying to write a program that opens a text file and manipulates the data. > > I have managed to open the text file into a textbox1 as a string > i now wish to add code to a...
9
5268
by: Someonekicked | last post by:
In my program, I need to open multiple files, and I wont know till after the program execution how many of them (user will enter that value). So I am using a vector of fstream. I am using fstream...
1
5334
by: MForey | last post by:
I'm attempting to create a program that uses fstream objects to read/write to files. However, it is currently balky at best. The fstream.write call doesn't return an error, but the modified data...
6
17102
by: wiso | last post by:
My problem is this (from: http://www.cplusplus.com/ref/iostream/fstream/open.html) #include <fstream> using namespace std; int main() { fstream f;
5
4146
by: neowillis | last post by:
code: #include <iostream> #include <fstream> #include <string> using namespace std; int main() {
8
2848
by: sabby | last post by:
I want to use the getline() so that i can enter a entire name in on line. (with spaces) The prob is that i am initializing the variable as "N/A" and saving it to a text file. it is declared as a...
6
3719
by: Gaijinco | last post by:
Should this do something? #include <fstream> #include <string> int main() { std::fstream filestr ("test.txt", std::fstream::in | std::fstream::out); std::string s="";
22
18105
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.