Type Conversion happens while writing to Logfile in VC++
-
I am trying to output certain int variables to my logfile. But upon viewing the logfile these varuiables are shown in hex. any idea why this happens? ofstream logfile; GetLocalTime(&st); sprintf(logfilename,"Myfilename_%d%02d%02d.log",st.wYear,st.wMonth,st.wDay); logfile.open(logfilename, ios::app); logfile <<"# Time is :: "<
-
I am trying to output certain int variables to my logfile. But upon viewing the logfile these varuiables are shown in hex. any idea why this happens? ofstream logfile; GetLocalTime(&st); sprintf(logfilename,"Myfilename_%d%02d%02d.log",st.wYear,st.wMonth,st.wDay); logfile.open(logfilename, ios::app); logfile <<"# Time is :: "<
I don't know why your stream uses hex format here. But you can set the format: ios_base::fmtflags - C++ Reference[^]. Because you are still using the C library function
sprintf
for the file name you might use it also for formatting the output. I still prefer this because it is often simpler (e.g. for date and times with leading zeroes). -
I am trying to output certain int variables to my logfile. But upon viewing the logfile these varuiables are shown in hex. any idea why this happens? ofstream logfile; GetLocalTime(&st); sprintf(logfilename,"Myfilename_%d%02d%02d.log",st.wYear,st.wMonth,st.wDay); logfile.open(logfilename, ios::app); logfile <<"# Time is :: "<
-
I just ran the above code and the values are all in decimal. There must be something else in your code that is causing the issue.
-
Actually this is only a part of the code. I have int variables declared and those are also displayed in hex in the logfile. will it have something to do with the settings while I build the same in Visual C++?
-
No, but somewhere you are setting the stream attributes to display all integers in HEX rather than DEC format.
-
Thanks a lot.. There are instances in the code where the stream is set to hex. Upon removal the same works fine. But is there a way without removing hex and set the stream back to display DEC ?