473,668 Members | 2,287 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\d ata.txt", ios::in | ios::binary |
ios::nocreate);
if(! myfile)
{
cerr << "Failed to open file.\n";
exit(EXIT_FAILU RE);
}

//start reading data
//1st record from Master
cout<<"\nThe size of record1 in bytes is "<< sizeof(record1) ;
myfile.read((ch ar*) &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_fil es;
cout<<"\nThe next file number to use in Master is "<<
record1.file_nu m;
cout<<"\nThe rest of record 1 is {{" << record1.zeroes
<<"}}\n";

//close file
myfile.close();

//exit
return 0;
}
Jul 19 '05 #1
1 2105

"lurkerboy" <lu*******@yaho o.com> wrote in message
news:qq******** *************** *********@4ax.c om...
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
3210
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
1226
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 button that will find a line in the string that begins with a certain letter eg I and when it does i want to insert a value eg 2 into a set character distance on the line. Can anyone help me with a loop that could do this or another way please?
9
5285
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 since I will need to write and read from files, and I am using those files as binary files. I made a sample of what's going on (below). Without using vector, everything works fine, but with using vectors, something is going wrong somewhere!?? ...
1
5345
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 doesn't show in the next read, or when I open the file itself. Additionally, I get a insufficient parameters error from if I remove the ios flags from the open--from what I have read, isn't fstream supposed to default the flags to ios::in|ios::out? I...
6
17140
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
4167
by: neowillis | last post by:
code: #include <iostream> #include <fstream> #include <string> using namespace std; int main() {
8
2858
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 string. look at the code: #include <iostream.h> #include <fstream> #include <cstdlib> #include <string> using namespace std; //Account data structure
6
3728
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
18134
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 programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
8459
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8374
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8890
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8575
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8653
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2784
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.