MSDN文章說:
「的輸入字符串爲可以被解釋 作爲指定類型的數值字符序列的功能停止在第一字符讀取 輸入字符串。它不能識別爲 的一部分。「
如果測試包含實際數字unicode字符串的代碼,你會看到正確的輸出:
printf("TEST 1: %d \n", _tstoi(_T("1")));
輸出:
TEST 1: 1
像@Ylisar表示,* TOI函數用於將數字值從字符串轉換爲整數變量。
以下代碼將輸出數字表示,但請注意const變量的指針表示形式。我已經離開了兩個版本,所以你可以看到其中的差別:
printf("TEST 1: %d \n", _tstoi(_T("1")));
printf("TEST a: %d \n", _tstoi(_T("a")));
WCHAR* b(_T("b"));
printf("TEST A: %d \n", _T("A"));
printf("TEST b: %d \n", *b);
輸出:在多http://msdn.microsoft.com/en-us/library/yd5xkb5c%28v=vs.80%29.aspx
如果要總結(累加)的值
TEST 1: 1
TEST a: 0
TEST A: 13457492
TEST b: 98
退房,我建議你檢查一下在這些事情上做出奇蹟的STL範圍函數。例如
#include <numeric>
#include <string>
printf("TEST a: %d \n", *_T("a")); // 97
printf("TEST b: %d \n", *_T("b")); // 98
wstring uString(_T("ba"));
int result = accumulate(uString.begin(), uString.end(), 0);
printf("TEST accumulated: %d \n", result);
結果:
TEST a: 97
TEST b: 98
TEST accumulated: 195
這種方式,你不必有,遍歷所有的值去。範圍函數真的很適合這樣的東西。
簽出更多的:http://www.sgi.com/tech/stl/accumulate.html
來源
2011-10-20 09:38:39
AzP
也許感興趣,喬爾的「絕對最低每一個軟件開發人員絕對,積極必須知道的關於Unicode和字符集(沒有藉口!)」 http://www.joelonsoftware.com/articles/Unicode.html – HostileFork