formatted file output

This is a discussion on formatted file output within the C++ Programming forums, part of the General Programming Boards category; I could use some help in figuring out how to format the output of my program when writing to a ...

  1. #1
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350

    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

    #include[fstream.h]
    #include[iostream.h]

    blah

    int sum;
    char inputRead;

    ifstream inFile;
    ofstream outFile;

    if(inFile.fail())
    blah

    if(outFile.fail())
    blah

    blah

    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

    ....567
    ..8345
    12456

    I've tried using iomanip with stuff like

    outfile.setiosflags(ios::right);
    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.

    TIA
    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
    Posts
    552
    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
    Posts
    1,683
    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, 04: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, 02:58 PM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21