473,398 Members | 2,188 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,398 software developers and data experts.

Questions about C++ Builder and File I/O

I use C++ Builder to create a simple project that can open a picture
and save some text information to a file
My question is that:

After I execute the open picture dialog(btn_OpenPicture) and open the
picture in the form, the write to file function(btn_SaveClick) doesn't
work anymore. Every time I click the save button, nothing changed in
the file.
But before the execution of open picture, it works normally.
Why does that happen? thanks

My code:
void __fastcall TForm1::btn_SaveClick(TObject *Sender)
{
int i;
double num[49];
ofstream outfile("Data.txt", ios_base::app);
if (!outfile)
return;
i = 20;
outfile << i << endl;
for (i = 0; i < 49; i++)
outfile << num[i] << " ";
outfile << endl;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btn_OpenPictureClick(TObject *Sender)
{
OpenPictureDialog1->Execute();
Image1->Picture->LoadFromFile(OpenPictureDialog1-
>FileName);
}
//---------------------------------------------------------------------------

Feb 2 '07 #1
2 3710

"reyalp" <vi*****@gmail.comwrote in message
news:11*********************@j27g2000cwj.googlegro ups.com...
>I use C++ Builder to create a simple project that can open a picture
and save some text information to a file
Your question would be more appropriate in:

borland.public.cppbuilder.vcl.components.using

at

forums.borland.com

- Dennis
Feb 2 '07 #2
On Feb 1, 10:42 pm, "reyalp" <vict...@gmail.comwrote:
I use C++ Builder to create a simple project that can open a picture
and save some text information to a file
My question is that:

After I execute the open picture dialog(btn_OpenPicture) and open the
picture in the form, the write to file function(btn_SaveClick) doesn't
work anymore. Every time I click the save button, nothing changed in
the file.
But before the execution of open picture, it works normally.
Why does that happen? thanks

My code:
void __fastcall TForm1::btn_SaveClick(TObject *Sender)
{
int i;
double num[49];
ofstream outfile("Data.txt", ios_base::app);
if (!outfile)
return;
i = 20;
outfile << i << endl;
for (i = 0; i < 49; i++)
outfile << num[i] << " ";
outfile << endl;}
Hello,

In the btn_SaveClick() function, you are writing the uninitialized
array num[] to the file. This may explain why the file contents change
only the first time you click the button. When you click the button
again, the same uninitialized array is written, and if the memory
where the array resides has not changed, then the file contents will
not change either.

I suspect you may have some variable scope confusion. When you open
your image, do you process some data out of it, and store the data in
another num[] array that is declared in the scope of the TForm1 class?
If that is what's happened, then your locally declared num[] array
will be accessed, and this might not be what you want.

Also, the output file is opened in append mode (ios_base::app).
Perhaps you meant to open it in output mode? In output mode, the
existing file contents are deleted before new contents are written.
Then you can also omit the second parameter to the std::ofstream
constructor, because it will open in output mode by default.

Regards,
Markus.

Feb 2 '07 #3

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

Similar topics

7
by: stormslayer | last post by:
Folks: I've been considering a shift to python. I currently use c++builder (borland) or perl. I do computational models / statistics programming, and was interested in python b/c it a. has...
2
by: Horny Porno-thologist | last post by:
Dear everyone, I managed to get most of my code (nesting documents etc.) worked out, but there are a few niggles. The first one is as follows: My first document is: <?xml version="1.0"...
1
by: Steven O. | last post by:
I am basically a hobbyist programmer, at the moment doing a little work experimenting with some AI stuff. I learned C++, and then tried to teach myself MFC using MS Visual C++ 6.0. I swore off of...
1
by: quincy451 | last post by:
Ok, some basic questions. I want to create a website with a table of data and a couple buttons that might take certain actions like bring up another table. I also want to present a form and have...
4
by: Megan | last post by:
Okay, I have a few questions regarding an Access database our company has. I should first mention that I'm not that knowledgable in Access and don't really know how to use it, but I am learning. We...
1
by: Justin Hanson | last post by:
Red Earth Technologies announces the release of version 1.5 of Superior SQL Builder, its SQL tool that allows users to build complete SQL scripts without typing any code. Superior SQL Builder...
2
by: Mike Turco | last post by:
I like using the expression builder for a lot of different things but it isn't always available when I want to use it, for example in the code window, or in all of the control properties. I am...
8
by: vbgunz | last post by:
Hello world, I tried looking everywhere for a decent Tkinter GUI builder and the closest I got to finding one before being horrified from looking at the source was vtcl @...
1
by: gowthams123 | last post by:
Dear All, Plz help me with this oracle form builder installation? I have installed SQL *PLUS Release 9.2.0.1.0 and then installed form builder 9.0.2.7.0. When i enter the following username...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.