0

I had a question about how to fix this code I have where I'm trying to go through and make everything lowercase then every first letter of a sentence - the one after a period space - uppercase. I'm doing something wrong, but I cannot figure out where I went wrong. My code hangs after creating the output file sucessfully. Why does my code hang? How can I fix it?

#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;

class Test
{
private:
    string fileIn;
    string fileOut;
    char ch;

    ifstream inFile;        //input file stream
    fstream outFile;        //output file stream
public:
    Test();         //constructor
    void getData();
    void testOpen();
    void validate();
    void outOpen();
    void transform();
    void close();
};

/************************Method Defintions*****************************/

Test::Test()
{

}

void Test::getData()
{
    cout << "Enter the input file name including file type and hit enter when finished." << endl << endl;
    getline(cin, fileIn);

    cout << "Enter an output file name including file type and hit enter when finished." << endl << endl;
    getline(cin, fileOut);
}

void Test::testOpen()
{
    inFile.open(fileIn);

    validate();
}

void Test::validate()
{
    if (!inFile)
    {
        cout << "The file could not be opened.";
        exit(1234);
    }
}

void Test::outOpen()
{
    outFile.open(fileOut, ios::out);
}

void Test::transform()
{
    //set all letters to lower case
    inFile.get(ch);
    while (!inFile.eof())
    {
        outFile.put(tolower(ch));
        inFile.get(ch);
    }

    //rewind to beginning
    inFile.seekg(0L, ios::beg);

    //make all letters after .space upper case
    inFile.get(ch);
    while (!inFile.eof())
    {
        if (inFile, fileIn, '. ')
        {
            inFile.get(ch);
            outFile.put(toupper(ch));

        }
    }
}

void Test::close()
{
    inFile.close();
    outFile.close();
}


/**************************************Driver*********************************/

int main()
{
    //variables
    Test object;        //object of class Testing

    //get data for opening files
    object.getData();

    //open in file and validate it opened
    object.testOpen();

    //open output file
    object.outOpen();

    //transform text from one file to another
    object.transform();

    //close files
    object.close();


    return 0;
}
netish
  • 1
  • 1
  • 2
    What are you trying with `if (inFile, fileIn, '. ')`? Also see [Why is iostream::eof inside a loop condition considered wrong?](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) – R Sahu Oct 27 '16 at 21:05
  • I was trying to access the filestream of inFile in the file: fileIn at the locations where '. ' occurs – netish Oct 29 '16 at 13:48

0 Answers0