A problem with user input filename in textBox

the following is a method from the class I wrote, and it works so long as I set the filename in the program where the method is called, rather than as user input.

I have a textBox for user input, which uses data type wchar_t stream. I am at a loss as to how to use wfstream. It does not simply replace fstream. (tried that in many ways.)

I either need an example on wfstream, or a different form of textBox that will use a char data type. (or your recommended fix for this problem that I'm not seeing.) (yea, I'm new to programming for windows.)

I'm using VS .net 2003

thank you for your time.

int bfile::add(char* filename, char_rec dat) // char_rec is a structure.
{
fstream filestr;
filestr.open (filename , fstream::in | fstream::out | fstream::app);
filestr.write((char*)&dat,(sizeof(dat)));
filestr.close();

return 0;
};
Last edited on
If you are passing char* it should work...are you sure that it is null terminated? "/0" at the end of the string. Also, if you using a stream, you could try passing it directly to the add(), and then call .str() and .c_str() functions of the stream/string respectively.
What's being passed from the windows form is wchar_t. That's why I'm having the problem. I'll look into .str() and .c_str() also though. I'm used to working with strings (arrays) so I was mindful of the null termination. Thank you.
Topic archived. No new replies allowed.