c++ - How do I format a variable argument TCHAR -


void logwriter::writelog(lpctstr log, const char ending, lptstr args, ...) {     tchar str[128] = {0};     int len = (sizeof(log)/sizeof(tchar));     len += sizeof(ending)/sizeof(char); //might switch ending tchar..might have      _stprintf_s(str, len+4, "%s()%c", log, ending);     myoutput.push(str);     //used output console testing     //if (args != null)     //{     //    va_list argptr;     //    va_start(argptr, args);     //    vfprintf(stdout, args, argptr);     //    va_end(argptr);     //} } 

so cool way print log console.. want able choose put log. decided redirect wcout either file, or console. when outputing console super easy because had

void logwriter::writelog(const char* log, const char ending, char* args, ...) {     std::wcout << log << "(";     if (args != null)     {         va_list argptr;         va_start(argptr, args);         vfprintf(stdout, args, argptr);         va_end(argptr);     }     std::wcout << ")" << ending << std::endl; } 

and life good...when single threaded program , logging went console. figured i'd use queue temporarily store lines in log. in seperate thread empty queue , sleep 500ms. works (i haven't done bunch of testing on yet speed/performance) sprintf function it's giving me gibberish in output. if rid of sprintf , push log queue outputs string correctly. leads me i'm doing wrong sprintf, need/want variable arguments go in there too..... hmm might mean change something. have few macros might affect..

#define write_start logwriter::writelog(__function__, '+') #define write_startf(_smsg, ...) logwriter::writelog(__function__, '+', _smsg, __va_args__)   //example of usage void test1(lpctstr lpcldevclass, lpctstr lpcldevname) {     write_startf(_t("*%s* %s"), lpcldevclass, lpcldevname); } void test2() {     write_start; } 

any ideas on how should this? thank you


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -