Link to home
Start Free TrialLog in
Avatar of sa3q
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
void addToFile(CString data,char* file)
{
	if(data == " "){}else{		
   ofstream log(file,ios::app);		
      log << data;
      log <<'\0';
      log.close();
	}
}

Open in new window

after excute it i found in the file only the address of data not the data


can any body fix that


thank you
 
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could use it as below -

log << data.GetString();

This will return you the right string depending on your build settings (unicode/multibyte)
Avatar of evilrix
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();
        }
}

Open in new window