I need to translate a TCHAR array into int, and soon float.
MSDN's page at:
says _tstol is the function to convert TCHAR to long.
That page also mentions the followoing header files:
#include <TCHAR.H>
#include <stdlib.h>
So I stick that stuff in my code, and I'm getting the
following error:
error C2065: '_tstol' : undeclared identifier
What am I doing wrong?
Thanks
Larry
You are failing to supply your exact code (using copy and paste) so we can
figure it out. The problem is probably a typo on your part. This works fine
for me:
#include <tchar.h>
#include <stdlib.h>
int main()
{
TCHAR str[] = _T("827398");
int x = _tstol(str);
return 0;
}
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)
Thanks John:
I don't know how to build console apps, but the following fails
with the same "error C2065: '_tstol' : undeclared identifier":
#include <windows.h>
#include <tchar.h>
#include <stdlib.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCVmdLine, int iCmdShow)
{
TCHAR str[] = _T("827398");
wchar_t wide_str[] = L"827398";
int x = _tstol(str);
int y = _wtoi(wide_str);
return 0;
}
Commenting out the _tstol() results in a compile. Stepping
with the debugger shows the wchar_t string properly converted to
int.
So this is not critical. I can roll my own TCHAR support with
"#ifdef UNICODE".
Still, it would be nice not to have to do that.
I'm using VC6 on Win98. This is my second Windows program, so I
expect this is the result of a mistake I'm making.
Don't work too hard on this one. I'll have lot's of critical
problems to bother you folks with in the future.
Thanks
Larry
I copied and pasted your code and it compiles fine for me. This is with VC7.
I can only guess that you have an out-of-date tchar.h file. Open it up and
see if you can find _tstol in it. My version of the file has it in two
places:
#define _tstol _wtol
and
#define _tstol atol
(guarded by #ifdefs).
If this is the problem, you can download the latest SDK from Microsoft for
free or order it on CD for a modest price (allegedly cost of shipping etc.).
Probably you have old Platform SDK where _tstol was not defined. Open
tchar.h file (right-click on it, then "Open document") and search for
_tstol. If it's not there, then define your own macro:
#ifndef _tstol
# ifdef _UNICODE
# define _tstol _wtol
# else /* ndef _UNICODE */
# define _tstol atol
# endif /* _UNICODE */
#endif /* _tstol */
Thanks Mohun:
No, I'm not sure. A search for "atoi" turned up a table
showing ascii, unicode and TCHAR equivalent functions.
I don't find _tcstol.
I think I've found my problem. But I haven't solved it yet.
I forgot to download and install the platform SDK on this
computer I'm borrowing.
Thanks
Larry
John Carson wrote:
< Snip >
> I can only guess that you have an out-of-date tchar.h file. Open it up and
> see if you can find _tstol in it. My version of the file has it in two
> places:
>
> #define _tstol _wtol
> and
> #define _tstol atol
>
> (guarded by #ifdefs).
>
> If this is the problem, you can download the latest SDK from Microsoft for
> free or order it on CD for a modest price (allegedly cost of shipping etc.).
Thanks John:
That's the problem. I'm borrowing my sister's PC and loaded
VC6 and it's service pack. But I forgot about loading the
platform SDK.
I'm bringing that down now. I'm glad she has a fast cable
internet connection.
Thanks
Larry
>Hi Experts:
>
> I need to translate a TCHAR array into int, and soon float.
>
> MSDN's page at:
>
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_atof.2c_.atoi.2c_._atoi64.2c_.atol.asp
>
>says _tstol is the function to convert TCHAR to long.
>
> That page also mentions the followoing header files:
>
> #include <TCHAR.H>
> #include <stdlib.h>
I'm using MS VC 6. I found a definition for _ttoi in tchar.h. I don't
see a definition of _ttol or _ttod. At least for the forseable future,
I care only about 32 bit computers, so I don't really need _ttol. And
I wrote my own _ttod (see below). It uses _tcstod, which is defined in
tchar.h
inline double _ttod( LPCTSTR sIn )
{ LPTSTR p = TNULL; return _tcstod( sIn, &p ); };
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com