Saturday, November 7, 2009

error C2664: 'fopen_s' : cannot convert parameter 2 from 'const wchar_t *' to 'const char *'

why we hate windows? Because it takes ages to figure out how to convert string (unicode) to string(ansi)...
java is slower but works without googling for an hour....

#include stdio.h;
const static void log(core::stringw filename){
const wchar_t *c = filename.c_str();
char *s = new char[1000];
size_t size = 1000;
size_t t = wcstombs_s(&size, s, 1000, c, 1000);

FILE *stream;
errno_t e = fopen_s(&stream, s, "a+"); /* apend file (add text to
a file or create a file if it does not exist.*/
fprintf(stream,"%s","This is just an example :)"); /*writes*/
fclose(stream); /*done!*/
}

No comments:

Post a Comment