无法获取正确写入输出文件的方法并且无法编辑

时间:2016-04-28 06:07:08

标签: c#

这是我的主要方法

static void Main()
    {
        int id, age, exp;
        double avgAge, avgExp, ageSum = 0, expSum = 0, empSum = 0;
        char type;
        double total = 0;

        OpenFiles();
        PrintReportHeadings();
        while ((lineIn = fileIn.ReadLine()) != null)
        {
            empSum++;
            ParseLineIn(out id, out type, out age, out exp);
            UpdateTotals(ref ageSum, ref expSum, age, exp);
            string eligibility = GetEligibility(type, age, exp);
            PrintDetailLine(id, type, age, exp, eligibility);

        }

        avgAge = CalcAvg(ageSum, empSum, out total);
        avgExp = CalcAvg(expSum, empSum, out total);
        PrintAvg(avgAge, avgExp);
        CloseFiles();
    }

这是我的PrintAvg方法:

static void PrintAvg(double avgAge, double avgExp)
    {
        fileOut.Write("\nAvg\t  {0:f1}  {1:f1}", avgAge, avgExp);
    }

我在VisualStudio中的输出文件

    Employee Report               

 ID  Age   Exp    Eligibility 
---- ---   ---    ----------- 
1235  45    20    lack of exp age
2536  55    21    lack of exp age
5894  60    30    lack age
4597  75    35    can retire
2597  35    10    lack of exp age
5689  40    20    lack of exp age
5489  55    39    lack age
5872  60    40    can retire
5569  55    25    can retire
5566  80    20    lack of exp
8865  59    35    can retire
5598  65    35    can retire

然后我的输出文件再次出现在记事本中......

            Employee Report               

 ID  Age   Exp    Eligibility 
---- ---   ---    ----------- 
1235  45    20    lack of exp age
2536  55    21    lack of exp age
5894  60    30    lack age
4597  75    35    can retire
2597  35    10    lack of exp age
5689  40    20    lack of exp age
5489  55    39    lack age
5872  60    40    can retire
5569  55    25    can retire
5566  80    20    lack of exp
8865  59    35    can retire
5598  65    35    can retire
Avg   57.0  27.5

记事本显示平均值,当我编辑PrintAvg方法尝试获得换行符以降低平均值下限时,它没有任何效果。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

Windows使用\ r \ n作为换行符。所以也许你应该尝试编写 \ r \ n 来获得所需数量的换行符。

static void PrintAvg(double avgAge, double avgExp)
{
    fileOut.Write("\r\nAvg\t  {0:f1}  {1:f1}", avgAge, avgExp);
}
相关问题