Open a file with a constructor

B

Brian

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::eek:ut|ios::app|ios::binary);
}

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

int main()
{
file_handler newfile("inventory.dat")
}
 
J

John Harrison

Brian said:
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
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top