将字符串转换成整数时,一般会用_ttoi()或_atoi(),但有时字符串转换后的整数比较大时,用int来保存结果可能就不够了。
这时,我们得用_atoi64()来转换,而且保存结果的数据类型要用__int64。看下面的例子:
#include <iostream.h>
#include <afx.h>
typedef
struct
_tagLongLong
{
UINT
n1;
UINT
n2;
}longlong;
int
main()
{
CString s =
"20110215160215"
;
// 时间:2011-2-15 16:02:15
__int64
n = _atoi64(s);
printf
(
"%I64d\n"
, n);
// cout<<n<<endl; // error C2593: 'operator <<' is ambiguous
return
0;
}
|
通过上面的_atoi64可以保存结果,但是用cout输出却无法输出(编译错误,因为没有重载<<用来输出__int64的)。用printf可以正确输出__int64类型的数据。