Thread: formatted file output

  1. #1
    Casual Visitor
    Join Date
    Oct 2001

    formatted file output

    I could use some help in figuring out how to format the output of my program when writing to a file.

    Bit of code



    int sum;
    char inputRead;

    ifstream inFile;
    ofstream outFile;




    outFile << sum << endl;

    What I'd like to do is to align the output to the right and fill smaller values with either a space or . So the output file would look like


    I've tried using iomanip with stuff like

    outFile << sum;

    But it returns an error stating something about converting longs to something else. I don't recall the exact error. I'd appreciate any help or ideas.

    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  2. #2
    Registered User
    Join Date
    Jan 2002
    Im not exactly sure cause I dont use iostream stuff much anymore, but it goes something like this:

    cout << setiosflags(ios::fixed) << setprecision(2);
    cout << setfill('.');
    cout << setw(10) << 45.56345 << endl;
    cout << setw(10) << 456.43345 << endl;

    or something like that

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    you can also use something like cout<<" blah blah blah... /n";
    the /n makes it to go to the next line

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  3. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM