0
我正在爲iPhone開發一個應用程序,其中我導入了C++ CLucene
庫。 幾乎所有的CLucene
函數都需要String
作爲TCHAR*
。如何將NSString轉換爲/從TCHAR(使用CLucene)
我在將NSString
轉換爲/從這種類型的數據中遇到了一些問題。我搜索了很多解決方案,但都沒有工作。
你能告訴我如何進行這種轉換嗎?
我能夠使用定義好的測試字符串with _T()
宏使庫工作。然而,XCode給我:
Conversion from string literal to 'TCHAR *' (aka 'wchar_t *') is deprecated.
哪個是不做過棄用的方法呢?
謝謝!
編輯: 我解決了這個辦法:
從NSString
到TCHAR*
轉換:
(const TCHAR *) [stringa cStringUsingEncoding:NSUTF32LittleEndianStringEncoding];
從TCHAR*
到NSString
轉換:
[[NSString alloc] initWithBytes:ctc length:wcslen(ctc) * sizeof(TCHAR) encoding:NSUTF32LittleEndianStringEncoding]
謝謝!
你可能想看看['this'](http://stackoverflow.com/questions/2610871/how-to-copy-a-wchar- t-into-nsstring)和['this'](http://stackoverflow.com/questions/891594/nsstring-to-wchar-t)。 –