__int64及_atoi64使用
将字符串转换成整数时,一般会用_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类型的数据。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步