1.字符串转换
数字转换为字符串:itoa
2.stl的string去掉左边空白,支持UNICODE
void TrimLeft(std::wstring &s)
{
int i=0;
int len = (int)s.length();
while(i<len)
{
TCHAR ch = s[i];
int white =
#ifdef UNICODE
iswspace(ch);
#else
isspace(ch);
#endif
if (!white)
{
break;
}
++i;
}
if (i<len)
{
s = s.substr(i);
}
}
3.数字转字符串
#define MAX_DIGITS_IN_INT 12 // max number of digits in an int (-2147483647 = 11 digits, +1 for the '\0')
std::string ToStr(int num, int base)
{
char str[MAX_DIGITS_IN_INT];
memset(str,0,MAX_DIGITS_IN_INT);
_itoa_s(num, str, MAX_DIGITS_IN_INT,base);
return std::string(str);
}