Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TCHAR string to int - _error C2065: '_tstol' : undeclared identifier

213 views
Skip to first unread message

Larry Lindstrom

unread,
Nov 19, 2003, 7:35:25 PM11/19/03
to
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>

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

John Carson

unread,
Nov 20, 2003, 12:28:43 AM11/20/03
to
"Larry Lindstrom" <la...@aracnet.com> wrote in message
news:3FBC0C4D...@aracnet.com


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)

Larry Lindstrom

unread,
Nov 20, 2003, 9:51:12 AM11/20/03
to

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

Mohun Biswas

unread,
Nov 20, 2003, 11:34:25 AM11/20/03
to
Are you sure you don't want _tcstol?

John Carson

unread,
Nov 20, 2003, 11:51:38 AM11/20/03
to
"Larry Lindstrom" <la...@aracnet.com> wrote in message
news:3FBCD4E0...@aracnet.com

>
> 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.).

Alex Blekhman

unread,
Nov 20, 2003, 12:16:38 PM11/20/03
to
"Larry Lindstrom" <la...@aracnet.com> wrote in message
news:3FBCD4E0...@aracnet.com...
>
> [...] 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.

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 */


Larry Lindstrom

unread,
Nov 20, 2003, 1:50:27 PM11/20/03
to
Mohun Biswas wrote:
> Are you sure you don't want _tcstol?

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

Larry Lindstrom

unread,
Nov 20, 2003, 2:51:55 PM11/20/03
to

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

r_z_...@pen_fact.com

unread,
Nov 21, 2003, 2:21:41 PM11/21/03
to
On Wed, 19 Nov 2003 16:35:25 -0800, Larry Lindstrom
<la...@aracnet.com> wrote:

>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

0 new messages