Solved

save lines to a file

Posted on 2001-08-05
12
219 Views
Last Modified: 2010-04-02

 I know the commands of saveing the lines from say richedit, but i know in borland it saves everything in richedit at that time, how would i go about adding some lines to and end of a file
 i am not sure if this is the case in visual c++ but if anyone out there can help me it would be greatly apreciated.

 Thanks for your time...:)
0
Comment
Question by:a1a2
  • 4
  • 2
  • 2
  • +4
12 Comments
 
LVL 4

Expert Comment

by:AssafLavie
ID: 6352968
To save a line to a file in std c++:
{
ofstream f("target.file);
f << "Line1" << endl;
or
f << "Line2\n";
}

(The first is more portable)
0
 
LVL 4

Expert Comment

by:AssafLavie
ID: 6352986
Well, you might want to add:

#include <fstream>
using std::ofstream;

at the begining of that code...
0
 
LVL 1

Expert Comment

by:ua1zcl
ID: 6353071
a1a2, say your IDE where you are doing. As i know, it is not correct simply add a line,
 bacuse file format structure will changed.
Alex.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:curri
ID: 6354953
I don't know about Borland's or which control are you using. If you are using the standard Win95 RichEdit control, you can get data from them with streams(once you get the data then you can save it to a file, like shown above). Check this link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_stream_operations_in_rich_edit_controls.asp

0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 200 total points
ID: 6360711
You can create a TStringList, and load the file into it.
Then, add each line from the string list to the rich edit control, and delete the string list.
Code may be as :
TStringList *tmpList = new TStringList;
tmpList->LoadFromFile("C:\\Whatever.txt");
for(int i=0;i<tmpList->Count;i++)
Memo1->Lines->Add(tmpList->Strings[i]);
delete tmpList;

I hope, it helps. Alex
0
 

Author Comment

by:a1a2
ID: 6363612
Ah, yes i get your drift, all answers have been helpful

with borland if thats the only way to do it, i guess i am screwed...:)

as the files i am loading is about 5meg full of data, so yeah maybe i have to resort to vc++

but i would of thought there was some simple command to add text/data or what ever to the end of a file with out actually opening it...

ill give it a few more days, before i award the points...thanks ya all...
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6376066
hi AlexVirochovsky,
The experts in this section have agreed to post Comments rather than Answers.  This provides more help for the question asker, since more experts are likely to see and respond to the question.  The question asker will get more diverse and useful information to help him solve his problem.

It may seem like a great way to get points -- locking a question so no other experts will look at it, but it really is unfair to all involved.  So please, post comments, like everybody else.  Thanks!

=-=-=-=-=-=-=-=-
hi ala2,
Is the file just plain text -- or does it have italics, font changes, tables, etc in it?

If it is just plain text, you can simply open the file, seek to the end, write some text and close it.  That would be a lot more efficient than opening it and streaming all 5MB of its data into a control and then writing it back out.

-- Dan
0
 

Author Comment

by:a1a2
ID: 6376864
What do you mean by locking the question??
i haven't touched anything...

i offered 200 points for some advise to this question

What you said was logical, i think i should of thought about this question a bit more, cause it is relitavly easy answer, but i guess i am still new to programming, thank for your comments...:)

How do i award the points??
0
 

Author Comment

by:a1a2
ID: 6376868
Ah, i get ya now...lol

sorry i thought you where talking to me..:)

Thanks again for your answers...:)
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6377972
a1a2,
You have awarded the points to AlexVirochovsky.  Was that your intention?  Did you use his TStringList idea?  Or did you just append to the text file as I suggested?

From this comment...

>>What you said was logical, i think i should of thought about this question a bit more, cause it is relitavly
easy answer, ...

..which you posted right after my comment, I think that you intended to give the points to me.

Please reply.  Thanks!

-- Dan
0
 

Author Comment

by:a1a2
ID: 6392985
Well, i did...But what can we do about it now??

ah dont worrie about it man...

If i post any more messages ill have to watch what i actually clicking...:)

thanks man....
0
 

Expert Comment

by:ComTech
ID: 6420577
a1a2, not to worry.  AlexVirochovsky will get to keep his/her points, we do not take them away.  I will open a question for Dan_Rollins and award him 200 points for the correct answer.  These point will not come from your bank, as I will absorb the points on my side.

We all make mistakes, that inludes us Moderators.

Consider this question closed, and I take care of the rest.

Thanks all,
ComTech
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java inner class, for the sole use of parameter passing 21 78
Add values of each row in an array 3 70
C++ help/ Toy problem 19 49
Indy 10 not Receiving UDP broadcast 3 43
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question