473,765 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Open Picture) and open the
picture in the form, the write to file function(btn_Sa veClick) 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_Sav eClick(TObject *Sender)
{
int i;
double num[49];
ofstream outfile("Data.t xt", 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_Ope nPictureClick(T Object *Sender)
{
OpenPictureDial og1->Execute();
Image1->Picture->LoadFromFile(O penPictureDialo g1-
>FileName);
}
//---------------------------------------------------------------------------

Feb 2 '07 #1
2 3732

"reyalp" <vi*****@gmail. comwrote in message
news:11******** *************@j 27g2000cwj.goog legroups.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.usin g

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_Open Picture) and open the
picture in the form, the write to file function(btn_Sa veClick) 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_Sav eClick(TObject *Sender)
{
int i;
double num[49];
ofstream outfile("Data.t xt", 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
2067
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 a library that connects to the R stats package b. has code that seems way more readable than anything else There is, however, at least for my work, a hard constraint. Execution
2
1613
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" encoding="UTF-8" standalone="yes"?> <WfMessage>
1
261
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 MFC, which was a nightmare, and have been playing with Borlands C++ Builder. In C++ Builder, creating forms and other GUI elements is much simpler than MFC, very similar to Visual Basic. In the store yesterday, I was looking at the C++ .Net...
1
1446
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 it be filled in over the web instead of locally. So the question is? What C++ builder classes, or form design tools would I use to get started on that and be headed in the right direction? Thanks,
4
1992
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 use Access as a Rolodex with names and addresses of clients and vendors, so it's made up of forms. First question: when I first open Access and the Main Switchboard pops up and I click Enter/View Contacts it brings me to the first entry in the...
1
1728
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 introduces new SQL scripting technology, allowing users to quickly and easily transform their database data. In version 1.5 this scripting technology has been extended and enhanced so that complex SQL scripts can be built in less time and with...
2
7369
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 usually stuck having to go into the database window, creating a new query, etc., and then right-clicking in a field and selecting build. Is there a shortcut key, a way to add a button to an Access toolbar, or something like that so I can use to...
8
2560
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 @ http://vtcl.sourceforge.net. The next closest thing was page @ http://page.sourceforge.net/ Page just didn't cut it for me and I got several errors from it whereas vtcl was almost a dream come true. it was not only perfect but I had a full fledged gui design up and...
1
12210
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 password database scott tiger oracle system seshadri (which i have set) oracle I get the folowing error ;
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8833
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
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
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5277
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...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
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
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.