0

Hey. Can someone help me with this parsing function? I'm not sure why it won't work. Whenever I test it with a valid input and output file it simply crashes.

void parse(string infilename,string outfilename)
{   string temp;
    ifstream infile(infilename.c_str());
    ofstream outfile(outfilename.c_str(), ofstream::app);
    if(!infile)
    {   cerr<<"Infile Not Working!";

    }
    if(!outfile)
    {   cerr<<"Infile Not Working!";
        
    }

    while(infile>>temp, !infile.eof())
    {
        string::iterator beg=temp.begin();
        string::iterator end=temp.end();

        while(beg!=end)
        {
            if(!isalpha(*beg))
                temp.erase(beg);
            beg++;
        }

        outfile<<temp<<" ";
    }
    infile.close();
    infile.clear();
    outfile.close();
    outfile.clear();
}
1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by avaitla
0

Never Mind. The problem was that the input file had some weird characters in it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.