为什么我的最终输出增加了额外的时间

时间:2018-10-08 00:01:27

标签: c++ iostream

所以我正在为一个类编写一个c ++程序,但我能很好地解决这个问题,但这又增加了一个额外的功能。到输出文件的末尾。我不知道为什么这样做,或者我做错了什么,还有指针吗?

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;

void conv(char& s);

void conv(char& s)
{
    s = toupper(s);
}

int main()
{
    ifstream inFile;
    inFile.open("message.txt");

    if (!inFile.is_open())
    {
        cout << "failed to access file!" << endl;
        exit(EXIT_FAILURE);
    }

    ofstream outFile;
    outFile.open("upper.txt");

    if (!outFile.is_open())
    {
        cout << "failed to access file!" << endl;
        exit(EXIT_FAILURE);
    }

    char next;
    while (!inFile.eof())
    {
        inFile.get(next);
        if (!isupper(next))
        {
            conv(next);
            outFile << next;
        }
        else
        {
            outFile << next;
        }

    }
    inFile.close();
    outFile.close();
    system("pause");
    return 0;
}

输入来自一个文件,其中 “今天,比尔·史密斯(Bill Smith)吃了3个苹果和2个梨。”

输出看起来像这样, “今天的比尔·史密斯吃了3个苹果和2个梨。”

0 个答案:

没有答案