cjm20
asked on
Problem writing listbox strings to a text file in C++; File contents are numbers instead of strings
Easiest thing in the world: writing strings to a text file that are fetched from a listbox in C++ 6.0(or so I thought).
Here's my code:
#include <iostream>
#include <fstream>
using namespace std;
ofstream myfile;
myfile.open("C:\MyFile.txt ");
m_listBox.GetText(0, strMyString);
myfile << strMyString << endl;
myfile.close();
The file gets created, and is written to. But when I open the file in windows explorer, instead of seeing the a string in the file, I see a number that looks like a memory address, such as 0034544C.
If I alter the code above, to write string like this:
myfile << "My Test String" << endl;
then the string gets written correctly.
So, the issue is perhaps with the call to the list box's GetText() function. However, in the debugger, the string variable I pass into the call to GetText() shows a valid string (in both the Watch window and when I mouse hover over the variable).
Any thoughts?
Thanks very much.
Here's my code:
#include <iostream>
#include <fstream>
using namespace std;
ofstream myfile;
myfile.open("C:\MyFile.txt
m_listBox.GetText(0, strMyString);
myfile << strMyString << endl;
myfile.close();
The file gets created, and is written to. But when I open the file in windows explorer, instead of seeing the a string in the file, I see a number that looks like a memory address, such as 0034544C.
If I alter the code above, to write string like this:
myfile << "My Test String" << endl;
then the string gets written correctly.
So, the issue is perhaps with the call to the list box's GetText() function. However, in the debugger, the string variable I pass into the call to GetText() shows a valid string (in both the Watch window and when I mouse hover over the variable).
Any thoughts?
Thanks very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfection. Simple matter of casting. Thanks a bunch.
Open in new window