我嘗試使用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