Hello.
I have a C++ function that ouputs a set of data text files. I pass the directory path of where I want the files to be stored to the function through a BSTR variable. I then need the function to take this path string and append it to the front of the name of each text file. For example:
DirPath = "C:\MyDocs\NewFolder"
Filename1 = "Textfile1.txt"
Filename2 = "Textfile2.txt"
Add the above to give:
Filename1 = "C:\MyDocs\NewFolder\Textfile1.txt"
Filename2 = "C:\MyDocs\NewFolder\Textfile2.txt"
Then output data into each of these files using ofstream.
Here is the code I have so far, however, nothing gets saved in the appropriate folder at all, and I don't know why. Where am I going wrong? It must be a pointer problem or something. Any help would be greatly appreciated. Thanks.
I have a C++ function that ouputs a set of data text files. I pass the directory path of where I want the files to be stored to the function through a BSTR variable. I then need the function to take this path string and append it to the front of the name of each text file. For example:
DirPath = "C:\MyDocs\NewFolder"
Filename1 = "Textfile1.txt"
Filename2 = "Textfile2.txt"
Add the above to give:
Filename1 = "C:\MyDocs\NewFolder\Textfile1.txt"
Filename2 = "C:\MyDocs\NewFolder\Textfile2.txt"
Then output data into each of these files using ofstream.
Here is the code I have so far, however, nothing gets saved in the appropriate folder at all, and I don't know why. Where am I going wrong? It must be a pointer problem or something. Any help would be greatly appreciated. Thanks.
Code:
LPSTR DirPath;
void MyFunction(BSTR DirPathArg)
{
DirPath = (LPSTR)DirPathArg;
OutputFiles();
}
void OutputFiles()
{
char filename1=*DirPath;
char *buffer1=&filename1;
strcat(buffer1,"\\Textfile1.txt");
char filename2=*DirPath;
char *buffer2=&filename2;
strcat(buffer2,"\\Textfile2.txt");
ofstream outfile1(buffer1);
outfile1<< "Data1";
[b]outfile1<< ... etc ...[/b]
ofstream outfile2(buffer2);
outfile2<< "Data2";
[b]outfile2<< ... etc ...[/b]
}