I found out (elsewhere) that strcpy and strcat do
not allocate memory.
In C++, to do the actions I was trying to do, space for the strings should be allocated with
new, and the memory thus obtained freed up with
free when youâre done with it.
If it is to be dynamic, the required space would need to be ascertained in some way.
But also in C++, using the variable type string will eliminate many of the issues involved.
Finally, if you create a string with string myVar; to pass the value to functions that require a poiter to char, use myVar.c_str(). For instance, where you would use:
Code:
char* myVar = "C:\\Temp\\MyFile.txt";
FILE *fp = {0};
fp = fopen(fName.c_str(), "r");
you would use:
Code:
string myVar;
myVar = "C:\\Temp\\MyFile.txt";
FILE *fp = {0};
fp = fopen(fName.c_str(), "r");