Every string API has TCHAR version which compiles both for Multibyte and Unicode. You can find this in MSDN topic for the function. For atoi, this is _tstoi:
int nNumber = _tstoi(strNumber.GetBuffer(strNumber.GetLength()));
Last edited by Alex F; February 21st, 2009 at 02:45 AM.
That is a macro that get expanded to different things depending on whether UNICODE is defined.
Take the example of atoi in this example.
atoi is for the non-unicode version and _wtoi is for the unicode version.
As Alex F mentioned, if you use _tstoi it would get expanded to either atoi or _wtoi depending on whether the build you are taking is a unicode build or not.
The _T("string") macro is used for strings which gets expanded to L"string" for unicode and simply "string" for non-unicode builds.
When I read a .txt file (made by NOtepad) with CFile class and then print on screen what I find on file, there are usually bad characters at the end. It doesn't matter if I read 5, 10 or 20 bytes.
Code:
CFile f;
f.Open(m_file, CFile::modeRead);
CHAR s[80];
int bytesread=f.Read(s,10);
f.Close();
m_out+=s; //m_out is "Cstring" linked to an EDIT CONTROL box)
UpdateData(FALSE);
(Im making an MFC app).
Should I declare "s" as unicode ? How is it ?
Or should I avoid CFile commands?
Last edited by Shadowrun; February 22nd, 2009 at 06:37 PM.
You're seeing "bad" characters because your character array is not NULL terminated. Just add the following to your code and you should be fine:
Code:
CFile f;
f.Open(m_file, CFile::modeRead);
CHAR s[80];
int bytesread=f.Read(s,10);
f.Close();
s[10] = 0; // NULL terminator - (the 10 is just the number of bytes you read).
m_out+=s; //m_out is "Cstring" linked to an EDIT CONTROL box)
UpdateData(FALSE);
Hope that helps.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
Bookmarks