Board index » cppbuilder » Using file streams in VCL console applications

Using file streams in VCL console applications

I'm having difficulty using input file streams (ifstream) in console
applications which include VCL support (i.e. "Use VCL" is clicked in the
Console Wizard"). I have a small test program, which consists of the
following code:

**********************************************************************
//--------------------------------------------------------------------------
-
#include <vcl.h>
#pragma hdrstop
#include <fstream.h>
//--------------------------------------------------------------------------
-
#pragma argsused
int main(int argc, char* argv[])
{
   ifstream is;
   if(argc != 2)
   {
      cout << "usage: test1 <file>" << endl;
      exit(16);
   }

   is.open(argv[1]);
   if(!is)
   {
      cout << "couldn't open file " << argv[1] << endl;
      exit(16);
   }
   else
   {
      cout << "opened file " << argv[1] << endl;
      is.close();
   }

   return 0;

Quote
}

 **********************************************************************

If I create a console application INCLUDING the VCL, then strange things
occurr, such as argc being 0 when it really isn't, and I'm allowed to open
non-existant files for input!!! However, if "Use VCL" isn't checked in the
console wizard, everything works as expected. Are there any known issues
with the VCL and the standard C++ I/O framework?

Thanks,
-Mike

 

Re:Using file streams in VCL console applications


Quote
Michael Skelton wrote:
> #include <fstream.h>

#include <fstream>

Quote
> Are there any known issues
> with the VCL and the standard C++ I/O framework?

It works for me using BCB4&5.

Michel
--
----------------------------------------
Michel Leunen
mailto:mic...@leunen.com
http://www.leunen.com/cbuilder/
----------------------------------------

Re:Using file streams in VCL console applications


Well, glad it's working for you, but it is a MESS from my perspective. From
what I can tell, ifstream (or one if it's ancestors, like basic_ios) is
overwriting memory. This is the second problem I've discovered while using
the standard C++ streams in conjunction with the VCL. It's beginning to look
like the two do NOT work well together, and I'm looking at the prospect of
returning to the C-style I/O functions. This is not appealing to me!!!

-Mike

Quote
"Michel Leunen" <m...@skynet.be> wrote in message

news:3eaed110$1@newsgroups.borland.com...
Quote
> Michael Skelton wrote:

> > #include <fstream.h>

> #include <fstream>

> > Are there any known issues
> > with the VCL and the standard C++ I/O framework?

> It works for me using BCB4&5.

> Michel
> --
> ----------------------------------------
> Michel Leunen
> mailto:mic...@leunen.com
> http://www.leunen.com/cbuilder/
> ----------------------------------------

Re:Using file streams in VCL console applications


Quote
"Michael Skelton" <mskel...@vrms.com> wrote in message

news:3eaff66a$1@newsgroups.borland.com...

Quote
> Well, glad it's working for you, but it is a MESS from my perspective.
From
> what I can tell, ifstream (or one if it's ancestors, like basic_ios) is
> overwriting memory. This is the second problem I've discovered while using
> the standard C++ streams in conjunction with the VCL. It's beginning to
look
> like the two do NOT work well together, and I'm looking at the prospect of
> returning to the C-style I/O functions. This is not appealing to me!!!

We had several problems also with std::ifstream etc with BCB5.  Mostly it
was leaking
memory according to memory sleuth and codeguard but there seemed to be some
cases where
it was trashing memory and it looked like it was from RW's basic_ios in most
cases.  We installed the
test version of BCB6 and the problems when away.

We haven't upgraded to 6 yet, though we may be doing it soon, so we had to
change everything to TFileStreams.
FWIW, we've experienced several problems with RW.  We've even had problems
with  std::numeric_limits
and std::string.  They seem to work OK with the STLPort version though.
There also
doesn't seem to be a problem with non VCL projects but I haven't tested that
very much.

Given the support for BCB5 and lack of bug fixes, we're deciding whether to
go to BCB6 or drop Borland altogether.

Re:Using file streams in VCL console applications


Thanks, Duane, at least I know I'm not hallucinating! I've heard that BCB6
uses a non-RW implemenation of the STL, so perhaps that is a step in the
right direction.

I also concur regarding streams in the context of non-VCL projects. All
problems seem to dissappear once VCL support is removed. Is this a problem
in RW's implementation, or the VCl? I have no idea. If I had my way, we'd
migrate to .NET before BCB6, but it would entail too much work. I've had my
fill of Borland.

-Mike

Quote
"Duane Hebert" <du...@nitrex.com> wrote in message

news:3eaffe63@newsgroups.borland.com...
Quote

> "Michael Skelton" <mskel...@vrms.com> wrote in message
> news:3eaff66a$1@newsgroups.borland.com...
> > Well, glad it's working for you, but it is a MESS from my perspective.
> From
> > what I can tell, ifstream (or one if it's ancestors, like basic_ios) is
> > overwriting memory. This is the second problem I've discovered while
using
> > the standard C++ streams in conjunction with the VCL. It's beginning to
> look
> > like the two do NOT work well together, and I'm looking at the prospect
of
> > returning to the C-style I/O functions. This is not appealing to me!!!

> We had several problems also with std::ifstream etc with BCB5.  Mostly it
> was leaking
> memory according to memory sleuth and codeguard but there seemed to be
some
> cases where
> it was trashing memory and it looked like it was from RW's basic_ios in
most
> cases.  We installed the
> test version of BCB6 and the problems when away.

> We haven't upgraded to 6 yet, though we may be doing it soon, so we had to
> change everything to TFileStreams.
> FWIW, we've experienced several problems with RW.  We've even had problems
> with  std::numeric_limits
> and std::string.  They seem to work OK with the STLPort version though.
> There also
> doesn't seem to be a problem with non VCL projects but I haven't tested
that
> very much.

> Given the support for BCB5 and lack of bug fixes, we're deciding whether
to
> go to BCB6 or drop Borland altogether.

Re:Using file streams in VCL console applications


Quote
Michael Skelton wrote:
> I also concur regarding streams in the context of non-VCL projects. All
> problems seem to dissappear once VCL support is removed. Is this a problem
> in RW's implementation, or the VCl? I have no idea. If I had my way, we'd
> migrate to .NET before BCB6, but it would entail too much work. I've had my
> fill of Borland.

I have STLPort 4.5.3 installed on my BCB5.  You can search Google for tips, as
I did because I don't remember, but it only took something simple like changing
the paths, I think.  It might be worth a try to see if it helps.

Re:Using file streams in VCL console applications


Quote
Duane Hebert wrote:
> We had several problems also with std::ifstream etc with BCB5.  Mostly it
> was leaking
> memory according to memory sleuth and codeguard but there seemed to be some
> cases where
> it was trashing memory

Hmm, it seems that I'd have to check again my applications using
ifstream and the VCL against memory leaks! But I've never had my memory
messed up due to the use of ifstream in a VCL application.

Michel
--
----------------------------------------
Michel Leunen
mailto:mic...@leunen.com
http://www.leunen.com/cbuilder/
----------------------------------------

Re:Using file streams in VCL console applications


Quote
"Michel Leunen" <m...@skynet.be> wrote in message

news:3eb0e8e3$1@newsgroups.borland.com...

Quote
> Duane Hebert wrote:

> > We had several problems also with std::ifstream etc with BCB5.  Mostly
it
> > was leaking
> > memory according to memory sleuth and codeguard but there seemed to be
some
> > cases where
> > it was trashing memory

> Hmm, it seems that I'd have to check again my applications using
> ifstream and the VCL against memory leaks! But I've never had my memory
> messed up due to the use of ifstream in a VCL application.

IIRC, I would get a memory leak with something like:

void whatever() {

std::ifstream infile;

Quote
}

I would also get them using std::getline.  In both cases, the call stack
traced back to the RW code behind it and usually pointed to a getmem type
function ...

Re:Using file streams in VCL console applications


Just check out my initial posting in this thread for a code sample
demonstrating the memory problem. After stepping over the declaration of an
ifstream object, argc is magically decremented to zero!

On other occassions, I've managed to use ifstreams with no noticable side
effects. But after witnessing the behavior I saw in such an elementary test
program, I'll refrain from using RW streams in the future. Although it took
substantially more effort, I was able to get by with TFileStream. I'll have
to investigate the STLPort stuff, though.

-Mike

Quote
"Michel Leunen" <m...@skynet.be> wrote in message

news:3eb0e8e3$1@newsgroups.borland.com...
Quote
> Duane Hebert wrote:

> > We had several problems also with std::ifstream etc with BCB5.  Mostly
it
> > was leaking
> > memory according to memory sleuth and codeguard but there seemed to be
some
> > cases where
> > it was trashing memory

> Hmm, it seems that I'd have to check again my applications using
> ifstream and the VCL against memory leaks! But I've never had my memory
> messed up due to the use of ifstream in a VCL application.

> Michel
> --
> ----------------------------------------
> Michel Leunen
> mailto:mic...@leunen.com
> http://www.leunen.com/cbuilder/
> ----------------------------------------

Other Threads