Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > write to output file query

Reply
Thread Tools

write to output file query

 
 
jeff_zhang446@yahoo.com
Guest
Posts: n/a
 
      09-01-2005
Hi,
I try to write some data structure into a file as below and would
appreciate if someone can give me some advice here.

The output file looks like below:

row(1) 100 1 0 0 0 0 0 0 0 1
row(2) 150 5 0 0 0 0 0 0 0 2
row(3) 160 7 0 0 0 0 0 0 0 3

row(4) 100, 160.0, 120.0,100.0, 1
row(5) 1, 0, 12, 12, 12, 12, 12, 2
row(6) 0.0, 1.0, 1.5, 1.8, 2.0 3
row(7) 1, 1, 1, 1, 1, 1; 4
row( 150, 98.0, 25.0, 56.0, 5
row(9) 0.8, 0.8, 0.9, 10, 12, 15, 6
row(10) 2.6, 8.7, 8.9, 6.5, 7.9; 7
row(11) 160, 46.0, 67.0, 86.0, 8
row(12) 5.8, 9..0, 7.6, 23, 45, 67; 9

note:row(i) - for reference only and will not be included in the output
file.

There are :
1. two categories in the file: row1-row3 and row4-row11.
2. 3 types here: 100 (row1), 150(row2) and 160(row3).
3. the last column of each of the line refers to the row number that
print on the file.
4. 2nd column of row(1)- row(3) is the row number as in(3) relate to
its type in category 2.
Eg: 2nd column type 100 in row(1) =1, which is same as the last
column value as in row(4).
2nd column type 150 in row(2) =5, which is same as the last
column value as in row(

I store my data in a link list.
list - type100
- type150
- type160
A. First I read the type100 and write part of the info in row(1).
Then I need to jump to category 2 to continue writing the other info
relate to it (row(4) tp row(7)).

B. I jump back to row(2) working on type150. From (A), I know that the
value I am going to print for the column2 is 5. Continue writing the
info, jump to category 2....

C. same as above.

I wonder how actually can I jump up and down writing all the info into
a file?

In what way I can do that? More importantly I do not how many lines I
need for each type in category 2.

thank you

jeff

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      09-01-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
> I try to write some data structure into a file as below and would
> appreciate if someone can give me some advice here.
>
> The output file looks like below:

[snip]
> I wonder how actually can I jump up and down writing all the info into
> a file?
>
> In what way I can do that? More importantly I do not how many lines I
> need for each type in category 2.


Well, it might be best to change your file format to something easier
to use, but if that's not an option, then you could write the first
"header" info (row 1), write bogus data for the missing header info
(rows 2 and 3), then write the rest of the data associated with row 1.
Then, use ostream::seekp() to jump backwards in the file to row 2,
write the row 2 header, jump to the end of the file, and write the rest
of the data associated with row 2. Etc. Etc.

For more on ostream::seekp(), see
http://www.cplusplus.com/ref/iostrea...eam/seekp.html.

Cheers! --M

 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      09-01-2005
(E-Mail Removed) wrote:
>

[snip]
>
> I wonder how actually can I jump up and down writing all the info into
> a file?


Well.
I would build up a second data structure, with the only purpose
to collect the data as it needs to be printed.

Then some algorithm builds up that structure and can modify or append
in that data structure in any way it wants to (or needs to).

Only after that, this data structure holds the complete data in a way
that is easy to write to the file without the need to 'jump around'
in the actual data. Everything has already been processed and 'flattened'
out, such that the actual file write is nothing more then a few loops
and write instructions.

--
Karl Heinz Buchegger
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
write to output file Query joy_julia446@yahoo.com C++ 1 09-06-2005 11:46 PM
How to write output of aspx file created to HTML programmatically G ASP .Net 0 08-17-2004 08:14 PM
Newbie: How do I filter output to the screen and writing the orginal output to a file? Mav Perl Misc 22 07-09-2004 09:56 PM
parse output screen ok but cant get desired output new file! chuck amadi Python 1 06-23-2004 02:16 PM
Error BC31019: Unable to write to output file '<filename>' Joel Finkel ASP .Net 1 08-15-2003 03:48 PM



Advertisments