我尝试使用CString::GetAt()
和_tstoi()
将CString
的最后一个字符转换为int
,但编译器返回我error C2065: '_tstoi' : undeclared identifier
。我想我必须包括一个头文件,我试过#include "tchar.h"
没有成功。错误尝试使用_tstoi
CString str = "something2";
int index = 0;
if (!str.IsEmpty())
{
index = _tstoi((char*)str.GetAt(str.GetLength() - 1));
}
编辑:我用VC++ 6.0
那么,从'GetAt'函数开始返回一个_single'char'_而'_tstoi'需要一个C风格的字符串(即'char *')。 –
要将单个字符'c'转换为整数,您可以简单地使用'c - '0''。 –
@JoachimPileborg做到了这一点,但编译器从未到达那里,因为它无法识别'_tstoi'。我尝试过使用'atoi',但是在运行时我想'atox.c'文件。 – MRM