sa3q
asked on
i have problem in c++ ofstream ?
hello,
my problem appear after i changed the character set to Unicode from project properties
the function i attached here
can any body fix that
thank you
my problem appear after i changed the character set to Unicode from project properties
the function i attached here
void addToFile(CString data,char* file)
{
if(data == " "){}else{
ofstream log(file,ios::app);
log << data;
log <<'\0';
log.close();
}
}
after excute it i found in the file only the address of data not the datacan any body fix that
thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use basic_ofstream to create the appropriate stream type depending on whether the project is Unicode or MBCS.
void addToFile(CString data,char* file)
{
if(data == " "){}else{
basic_ofstream<TCHAR> log(file,ios::app); // <-- will always be correctly wide or narrow
log << data;
log <<'\0';
log.close();
}
}
log << data.GetString();
This will return you the right string depending on your build settings (unicode/multibyte)