加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 将int的地址转换为char指针的正确方式

发布时间:2020-12-16 03:14:22 所属栏目:百科 来源:网络整理
导读:如果我需要从ifstream读取int int myInt = 0;fileStream.read(reinterpret_castchar*(myInt),sizeof(int)); 正在使用reinterpret_cast char *正确的方式来完成这个 解决方法 is using reinterpret_cast correct way to accomplish that? 是.喜欢c风格的风格,
如果我需要从ifstream读取int
int myInt = 0;
fileStream.read(reinterpret_cast<char*>(&myInt),sizeof(int));

正在使用reinterpret_cast< char *>正确的方式来完成这个

解决方法

is using reinterpret_cast correct way to accomplish that?

是.喜欢c风格的风格,而不是c风格的风格.

正如评论中所建议的,使用read method function的更好的方法是:

int myInt = 0;
fileStream.read(reinterpret_cast<char*>(&myInt),sizeof(myInt));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读