Can someone look at my code and give me any idea why I'm getting abnormal program termination after the output is on the screen? It's just a simple program to open a file and then compare some letters for output. Thanx in advance.
#include <fstream> // For file i/o
#include <iomanip> // For cout manipulation
#include <iostream> // For cout
#include <stdlib.h> // For exit
#include <string> // For elements of type char
#include <stdio.h>
using namespace std;
int main ()
{
ifstream Code_Detail;
ofstream Code_Out;
string line;
string Prefix, DocAreaCode2, Description; // Strings for Code_Detail
Code_Detail.open ("Code_Detail.txt");
if (Code_Detail.fail ())
{
cout << "Cannot Open File: " << endl;
return EXIT_FAILURE;
}
Code_Out.open ("Code_Out.txt");
if (Code_Out.fail ())
{
cout << "Cannot Create File: " << endl;
return EXIT_FAILURE;
}
while (Code_Detail.good ())
{
getline(Code_Detail, line);
Prefix=line.substr(0,2);
DocAreaCode2=line.substr(2,2);
Description=line.substr(4,11);
if ((Prefix == "AA") && (Description == "MC"))
{
cout << Prefix << DocAreaCode2 << Description << endl;
Code_Out << Prefix << DocAreaCode2 << Description << endl;
}
}
Code_Detail.close ();
Code_Out.close ();
return EXIT_SUCCESS;
}