Hi,
Im pretty new to c++ programming so plz dont be offended if i ask "stupid" questions.
Im want to open a file named "Alexander".
The name of the file is stored in an Ansisting.
So i want to add an ".txt" extension to open the file.
Then i want to read a line form the file and store it in an string named StringFromFile.
The only problem was that i get an Acces violation. So i searched for some treads on this site and found the following tread:
http://www.daniweb.com/forums/newthread.php?do=newthread&f=8
After reading it i figured out that this char array may be stored in read-only memory. So my question is: is the acces violation generated because om trying to add ".txt" to char* temp?
I already have a solution by using char temp[] but i would still like to understand why the acces violation was genereted!
AnsiString filename = "Alexander";
std:string StringFromFile;
char* temp = filename.c_str();
strcat(temp, ".txt");
ifstream myfile3;
myfile3.open (temp);
getline(myfile3, StringFromFile);
myfile3.close();
delete[] temp;