Hello, i'm having a problem where my program is crashing everytime it reachs a certain point. I get the error "test001.exe has encountered a problem and needs to close. we are sorry for the inconvenience".
Now, i've put cout << "display"; on every line to see where the crash occurs, and it happens with this statement
"if (strcmp(line.c_str(), "Importance: High")==0 )",
i've tried replacing it with "if (line == "Importance: High"){", yet it still crashes.
Im using visual studio 2008, but when compiled on my friends dev-c++ the code works fine. I can't switch IDE though. Im not sure what is going on here.
If I press debug I get the message "An unhandled win32 exception occurred in test001.exe [4612]. Then when I open the debugger I get "unhandled exception at 0x1049191c (msvcp90d.dll) in test001.exe:0xC0000005:Access violation reading location 0x00000018.
It then goes to the xstring file and goes to this line:
size_type __CLR_OR_THIS_CALL length() const
{ // return length of sequence
return ( Mysoze);
}
the following screenshot shows more detail:
http://img15.imageshack.us/my.php?image=errorrki.jpg
Code------
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string checkpriority (string filenameandpath);
int main( )
{
string passtocheckpriorityfunction;
string priorityresult;
cout << "Enter the file path and name: ";
getline( cin, passtocheckpriorityfunction );
priorityresult = checkpriority(passtocheckpriorityfunction);
ofstream myoutputfile( "result.txt" );
myoutputfile << priorityresult;
myoutputfile.close();
return 0;
}
string checkpriority (string filenameandpath) { // my function
string line;
cout << "Opening file..." << std::endl;
cout << filenameandpath << std::endl;
fstream myinputfile;
myinputfile.open( filenameandpath.c_str(), ios::in | ios::out );
if (myinputfile.is_open())
{
while ( !(myinputfile.eof()) )
{
getline(myinputfile,line);
if (strcmp(line.c_str(), "Importance: High")==0 )
{
cout << "Found match." << std::endl;
return "Importance: 1.\n";
}
}
myinputfile.close();
}
}