So I am writing a c++ program for a class and I got it to work out just fine but it is adding an extra . to the end of the output file. I don't know why it's doing this or what I have done wrong, any pointers?
#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;
}
the input is from a file that says, "Today Bill Smith ate 3 apples and 2 pears."
the output comes out looking like this , "TODAY BILL SMITH ATE 3 APPLES AND 2 PEARS.."