944,175 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1400
  • C RSS
Aug 23rd, 2005
0

Formatting with Filestream Pointers...

Expand Post »
I am having trouble setting the output format while using a pointer to a Filestream:

  1. struct statLine{
  2. int id;
  3. int primary_type;
  4. int secondary_type;
  5. double period;
  6. double epochnumber;
  7. int savedextremenumber;
  8. }statLine;
  9.  
  10. void printStatLine(ofstream *FSOptr)
  11. {
  12. FSOptr->precision(7);
  13. *FSOptr << statLine.id << " " << statLine.primary_type << " " <<statLine.secondary_type << " ";
  14. *FSOptr << statLine.period << " ";
  15. *FSOptr << statLine.epochnumber << " " << statLine.savedextremenumber << endl;
  16. }

The printing works ok, but I can't seem to make the formatting (precision(7)) stick. Any suggestions?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Analogsleeper is offline Offline
13 posts
since Aug 2005
Aug 24th, 2005
0

Re: Formatting with Filestream Pointers...

do you mean setprecision()?
yer gonna need to insert it into the stream before your data likeso

struct statLine{
int id;
int primary_type;
int secondary_type;
double period;
double epochnumber;
int savedextremenumber;
}statLine;

void printStatLine(ofstream *FSOptr)
{
        //FSOptr->precision(7);
        *FSOptr << statLine.id << " " << statLine.primary_type << " " <<statLine.secondary_type << " ";
        *FSOptr << setprecision(7) << statLine.period << " ";
        *FSOptr << setprecision(7)  << statLine.epochnumber << " " << statLine.savedextremenumber << endl;
}
dont forget to add <iomanip> up top
Reputation Points: 10
Solved Threads: 3
Newbie Poster
nattylife is offline Offline
14 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: printf & cout
Next Thread in C Forum Timeline: abt algoritham complexity





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC