473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Open a file with a constructor

I am trying to open a file in the classes contructor. The file is
created and the program even thinks it is open and tries to write to
it with no errors, but when I look at the file it is zero
bytes..nothing was written to it. Here is part of my code if anyone
can help me. I do appreciate it.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include "stdio.h"

using namespace std;

class file_handler
{
private:
ofstream outfile;
public:

char InventoryNumber[16];
char ProductName[21];
char ProductCode[4];
int OnHandQuantity;
int BackOrderQuantity;
int OnOrderQuantity;
float InventoryEvaluation;
float AverageCost;
float SellingPrice;

file_handler();
file_handler(string file);
~file_handler();
int write_file();
file_handler::~file_handler()
{
outfile.close();
}

file_handler::file_handler(string file)
{
outfile.open(file.c_str(),ios::out|ios::app|ios::b inary);
}

file_handler::write_file()
{
//writing file stuff
}

int main()
{
file_handler newfile("inventory.dat")
}
Jul 22 '05 #1
1 3900

"Brian" <co*****@gmail.com> wrote in message
news:6a*************************@posting.google.co m...
I am trying to open a file in the classes contructor. The file is
created and the program even thinks it is open and tries to write to
it with no errors, but when I look at the file it is zero
bytes..nothing was written to it. Here is part of my code if anyone
can help me. I do appreciate it.


[snip]

No, there is no problem with the code you've posted that I can see. The
problem is probably somewhere in the code you haven't posted. Perhaps you
never get to call write_file, or perhaps there is a bug in write_file.

If you want problems with code fixed, it is always a good idea to post
complete programs, preferably cut down to the part that isn't working.

john
Jul 22 '05 #2

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

Similar topics

1
by: tornado | last post by:
hi all, This is quite puzzling me why is that ofstream constructor is unable to open a file for writing while, a ofstream "open" method can ! The c++ book by Herbert Schildt which i m readin...
4
by: Otik | last post by:
Hi, I'm trying to open a file with read access only, e.g. FileStream fs = new FileStream("C:\foo.txt", FileMode.Open, FileAccess.Read); The file is open by another process and the FileStream...
8
by: Peter A. Schott | last post by:
Been reading the docs saying that file should replace open in our code, but this doesn't seem to work: # Open file for writing, write something, close file MyFile = file("MyFile.txt", "w")...
115
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i...
3
by: trellow | last post by:
Hello, I am writing an application that needs to read a file that is already open by another process for writing. When I do the following: FileStream fs = new FileStream(fileName,...
9
by: Charles F McDevitt | last post by:
I'm trying to upgrade some old code that used old iostreams. At one place in the code, I have a path/filename in a wchar_t string (unicode utf-16). I need to open an ifstream to that file. ...
7
by: Drew | last post by:
I have a small VB.NET application that captures left clicks, right clicks and key presses and automatically logs them to a csv file every 1 minute. The issue is that if I want to look at the log...
5
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end....
4
by: nickyeng | last post by:
i have main program, which user key in the filename in command line argument. i pass the argument to another class constructor to handle it. I have the filename correct, but it still give me...
20
by: Author | last post by:
a .net 1.1 app has a class whose constructor opens a db connection to sql svr two thousand. this class has more than a dozen of methods. most of them don't do db stuff. I am wondering if this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.