Thread: output format: screen vs .txt

  1. #1
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79

    output format: screen vs .txt

    another n00b question -

    How do you you get your .txt file output to match the screen? I'm getting the hang of creating presentable output but when I save it to a text file it's all out of whack.

    Is it just fonts? Anybody know what the default fonts are in a console app?

    Thanks -

    JM

    (Oh yeah, running XP pro, Dev-C++, opening .txt files in Notepad)
    Huh?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It should look pretty much the same in Notepad, since Notepad uses a fixed-width font like the console does. Can you give an example of the output (in code tags) that doesn't look right?

  3. #3
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    Code:
    Rusty Shackleford
    Gross Amount: ................ $ 3575.00
    Federal Tax: ................. $  536.25
    State Tax: ................... $  125.13
    Social Security Tax: ......... $  205.56
    Medicare/Medicaid Tax: ....... $   98.31
    Pension Plan: ................ $  178.75
    Health Insurance: ............ $   75.00
    Net Pay: ..................... $ 1137.00
    On the screen this lays out in nice straight columns.

    (Edit - as you can see, but in Notepad it looks crappy!)
    Huh?

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Looks fine in Notepad for me. Are the '.'s actually periods, or are they spaces or tabs? Did you copy and paste that output from the console or from the text file? Are you sure you're not accidentally using Wordpad?

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    Make sure you are using a fixed-width font
    Courier
    Courier New
    for example.

  6. #6
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    That was cut/pasted from the .txt file, and the '.'s are periods. I'm opening it in Notepad, and I'm using whatever the default fonts are.

    This is an exercise from "C++ Programming" by D.S. Malik - it's early in the book so there are no loops or functions.

    Code:
    #include<iostream>
    #include<fstream>
    #include<iomanip>
    
    using namespace std;
    
    int main()
    {
        const int Fed = 15, PP = 5; 
        const double State = 3.5, SS = 5.75, MM = 2.75, Health = 75;
        double Gross, Temp, Net;
        string Name;
        const int c1=30, c2 = 8;
        
        ofstream outFile;
        
        outFile.open("E:\\paycheck.txt");
        
        cout<<"Please enter your name: ";
        getline(cin,Name);
        cout<<"and your gross pay: ";
        cin>>Gross;
        cout<<endl;
        Net = Gross;
        
        cout<<Name<<endl;
        cout.fill('.');
        cout<<fixed<<showpoint<<setprecision(2);
        cout<<left<<setw(c1)<<"Gross Amount: "<<" $";
        cout.fill(' ');
        cout<<right<<setw(c2)<<Gross<<endl;
        
        Temp = Gross*Fed/100;
        Net=Net-Temp;
        cout.fill('.');
        cout<<left<<setw(c1)<<"Federal Tax: "<<" $";
        cout.fill(' ');
        cout<<right<<setw(c2)<<Temp<<endl;
        
        Temp = Gross*State/100;
        Net=Net-Temp;
        cout.fill('.');
        cout<<left<<setw(c1)<<"State Tax: "<<" $";
        cout.fill(' ');
        cout<<right<<setw(c2)<<Temp<<endl;
        
        Temp = Gross......../100;
        Net=Net-Temp;
        cout.fill('.');
        cout<<left<<setw(c1)<<"Social Security Tax: "<<" $";
        cout.fill(' ');cout.fill(' ');
        cout<<right<<setw(c2)<<Temp<<endl;
        
        Temp = Gross*MM/100;
        Net=Net-Temp;
        cout.fill('.');
        cout<<left<<setw(c1)<<"Medicare/Medicaid Tax: "<<" $";
        cout.fill(' ');
        cout<<right<<setw(c2)<<Temp<<endl;
        
        Temp = Gross*PP/100;
        Net=Net-Temp;
        cout.fill('.');
        cout<<left<<setw(c1)<<"Pension Plan: "<<" $";
        cout.fill(' ');
        cout<<right<<setw(c2)<<Temp<<endl;
        
        Net=Net-Health;
        cout.fill('.');
        cout<<left<<setw(c1)<<"Health Insurance: "<<" $";
        cout.fill(' ');
        cout<<right<<setw(c2)<<Health<<endl;
        
        cout.fill('.');
        cout<<left<<setw(c1)<<"Net Pay: "<<" $";
        cout.fill(' ');
        cout<<right<<setw(c2)<<Net<<endl;
        
        // Here's the outFile part
        
        outFile<<Name<<endl;
        outFile.fill('.');
        outFile<<fixed<<showpoint<<setprecision(2);
        outFile<<left<<setw(c1)<<"Gross Amount: "<<" $";
        outFile.fill(' ');
        outFile<<right<<setw(c2)<<Gross<<endl;
        
        Temp = Gross*Fed/100;
        Net=Net-Temp;
        outFile.fill('.');
        outFile<<left<<setw(c1)<<"Federal Tax: "<<" $";
        outFile.fill(' ');
        outFile<<right<<setw(c2)<<Temp<<endl;
        
        Temp = Gross*State/100;
        Net=Net-Temp;
        outFile.fill('.');
        outFile<<left<<setw(c1)<<"State Tax: "<<" $";
        outFile.fill(' ');
        outFile<<right<<setw(c2)<<Temp<<endl;
        
        Temp = Gross......../100;
        Net=Net-Temp;
        outFile.fill('.');
        outFile<<left<<setw(c1)<<"Social Security Tax: "<<" $";
        outFile.fill(' ');cout.fill(' ');
        outFile<<right<<setw(c2)<<Temp<<endl;
        
        Temp = Gross*MM/100;
        Net=Net-Temp;
        outFile.fill('.');
        outFile<<left<<setw(c1)<<"Medicare/Medicaid Tax: "<<" $";
        outFile.fill(' ');
        outFile<<right<<setw(c2)<<Temp<<endl;
        
        Temp = Gross*PP/100;
        Net=Net-Temp;
        outFile.fill('.');
        outFile<<left<<setw(c1)<<"Pension Plan: "<<" $";
        outFile.fill(' ');
        outFile<<right<<setw(c2)<<Temp<<endl;
        
        Net=Net-Health;
        outFile.fill('.');
        outFile<<left<<setw(c1)<<"Health Insurance: "<<" $";
        outFile.fill(' ');
        outFile<<right<<setw(c2)<<Health<<endl;
        
        outFile.fill('.');
        outFile<<left<<setw(c1)<<"Net Pay: "<<" $";
        outFile.fill(' ');
        outFile<<right<<setw(c2)<<Net<<endl;
         
        outFile.close();
        
        cin.ignore();
        cin.get();
        
        return 0;
    }
    Huh?

  7. #7
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Sounds like you aren't using a fixed-width font for notepad. Did you try (in notepad's menu) Format->Font... then choose "Lucida Console" (that's what mine is set to, at least)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  8. #8
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    Well there we go - thanks!
    Huh?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 06:25 AM
  2. How do you output the contents of a console screen to file?
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2005, 08:26 AM
  3. Control different DA output value!
    By Hunterhunter in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-13-2003, 12:11 PM
  4. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM
  5. Saving screen output to file
    By Gkitty in forum C Programming
    Replies: 7
    Last Post: 12-20-2002, 12:38 AM