| | |
Error trying to write to existing file
![]() |
Hi, I'm new to the forum and need some help writing my first 'complicated' program.
I have trouble writing to an existing file.
I want to write to an Excel file I already created and edited exclusively for the program I wrote, but when I write the data it destroys all the editing of the file and I don't know what's wrong or if it's even possible to do what I'm trying to.
Im pretty sure all the writing to the file goes in blank spaces, so I don't know what is the problem.
I'm following the commands (the only one I know to write to files) described below:
fout.open("Character.xls");
// loads of output text
fout.close();
All my program works fine except for the writing to the Excel file, I don't get any errors.
Well, I think that's it
Hope somebody can help me soon.
I have trouble writing to an existing file.
I want to write to an Excel file I already created and edited exclusively for the program I wrote, but when I write the data it destroys all the editing of the file and I don't know what's wrong or if it's even possible to do what I'm trying to.
Im pretty sure all the writing to the file goes in blank spaces, so I don't know what is the problem.
I'm following the commands (the only one I know to write to files) described below:
fout.open("Character.xls");
// loads of output text
fout.close();
All my program works fine except for the writing to the Excel file, I don't get any errors.
Well, I think that's it
Hope somebody can help me soon.
Data type is usually the most important thing to include -- how is fout declared? If it is an ofstream, you are using the default mode, which I believe means to truncate an existing file. I think you would need to use an fstream opened for read/write ("r+" in fopen-speak), perhaps even in binary mode as well.
http://www.dinkumware.com/htm_cpl/fs..._filebuf::open
http://www.dinkumware.com/htm_cpl/fs..._filebuf::open
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Okay, I tried something from the link you posted, but I just got more confused :lol:
I'll post you what im using now:
<< moderator edit: added [code][/code] tags >>
I'm still using the fout because the compiler tells me its necessary to input the data, but now the program wont return me anything, it leaves the file in blank, just like it was. So:
1. Do I have to create another way of calling a file output?
2. Do I need something else than #include <fstream>?
I've worked in this program four days in a row, just stopping to eat, sleep and other neccessities, and now that I've reached the end it just seems I worked for nothing. Its frustating, please help :cry:
Im kind of new to programming, only the past 2 weeks with tutorials all by myself, if you can explain something to me I'm willing to learn, just go easy
I'll post you what im using now:
C Syntax (Toggle Plain Text)
filebuf iobuf; iobuf.open("Character.xls",ios_base::in | ios_base::out); \\ loads of input text iobuf.close();
I'm still using the fout because the compiler tells me its necessary to input the data, but now the program wont return me anything, it leaves the file in blank, just like it was. So:
1. Do I have to create another way of calling a file output?
2. Do I need something else than #include <fstream>?
I've worked in this program four days in a row, just stopping to eat, sleep and other neccessities, and now that I've reached the end it just seems I worked for nothing. Its frustating, please help :cry:
Im kind of new to programming, only the past 2 weeks with tutorials all by myself, if you can explain something to me I'm willing to learn, just go easy
•
•
•
•
Originally Posted by Yoshidex
Okay, I tried something from the link you posted, but I just got more confused :lol:
•
•
•
•
Originally Posted by Yoshidex
I'll post you what im using now:
<< moderator edit: added [code][/code] tags >>C Syntax (Toggle Plain Text)
filebuf iobuf; iobuf.open("Character.xls",ios_base::in | ios_base::out); \\ loads of input text iobuf.close();

•
•
•
•
Originally Posted by Yoshidex
I'm still using the fout because the compiler tells me its necessary to input the data, but now the program wont return me anything, it leaves the file in blank, just like it was. So:
1. Do I have to create another way of calling a file output?
2. Do I need something else than #include <fstream>?
The page I linked to was to help explain the open modes.
Also, this
C Syntax (Toggle Plain Text)
// loads of output text
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
I'm really sorry, I forgot your question.
Yes, fout is ofstream.
Theres is a lot of output text, so I didn't want to get anyone bored, well, if you're asking for it, here it is, my complete code.
I didn't attach the header file because is way too messy, after all, Im noob :cheesy: , but I think this holds everything you need to detect a problem.
Thank you for your time.
Yes, fout is ofstream.
Theres is a lot of output text, so I didn't want to get anyone bored, well, if you're asking for it, here it is, my complete code.
I didn't attach the header file because is way too messy, after all, Im noob :cheesy: , but I think this holds everything you need to detect a problem.
Thank you for your time.
Last edited by Yoshidex; Jun 28th, 2005 at 6:57 pm. Reason: Attach file not found
•
•
•
•
I didn't attach the header file because is way too messy, after all, Im noob , but I think this holds everything you need to detect a problem.

C Syntax (Toggle Plain Text)
ofstream fout; // ... filebuf iobuf; iobuf.open("Character.xls",ios_base::in | ios_base::out);
fstream fout; // ... fout.open("Character.xls",ios_base::in | ios_base::out);
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Now it writes at the top of the file, destroys all my editing done in the file and returns funny characters after all of the data was input. It looks very weird, and funny at the same time. Well, this happen after I did what you told me too in your last reply.
I'll add the header file, too bad I can't attach the Excel file, I really made it look good.
Thanks again, I really appreciate that you are responding to my messages.
Theres a few things you need to know about my program:
After buying the first weapon and returning to the menu of weapons you must quit or will be charged and what you already bought will be deleated, same for the second weapon.
I'll add the header file, too bad I can't attach the Excel file, I really made it look good.
Thanks again, I really appreciate that you are responding to my messages.
Theres a few things you need to know about my program:
After buying the first weapon and returning to the menu of weapons you must quit or will be charged and what you already bought will be deleated, same for the second weapon.
Code in a header...! You have much to learn young grasshopper.
Sorry I haven't been that great of a help thus far. But have you considered outputting your data to a bland old .tsv file and then use Excel's wonderful import abilities to spruce things up on that end?
Sorry I haven't been that great of a help thus far. But have you considered outputting your data to a bland old .tsv file and then use Excel's wonderful import abilities to spruce things up on that end?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Thanks again,
I have some more doubts:
What is a .tsv file?
I did it but no file appears in the directory. "Character.tsv"
And how do i get excel to import it and paste it where i want to?
I tell you, now that I'm remembering, I only have a week programming, any suggestions will be happily accepted. :mrgreen:
I have some more doubts:
What is a .tsv file?
I did it but no file appears in the directory. "Character.tsv"
And how do i get excel to import it and paste it where i want to?
I tell you, now that I'm remembering, I only have a week programming, any suggestions will be happily accepted. :mrgreen:
Last edited by Yoshidex; Jun 28th, 2005 at 7:31 pm. Reason: Forgot
![]() |
Other Threads in the C Forum
- Previous Thread: Threading (multi threading) in Linux
- Next Thread: Random Number Guessing Game
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






