在C / C ++中读取字节方法 [英] Read bytes methods in C / C++

查看:151
本文介绍了在C / C ++中读取字节方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的C,我想知道是否有标准库方法读取bytes / int / long
如:getChar(),getInt(),getLong()。

I am new to C and i was wondering if there are standard library methods to read bytes/int/long such as: getChar(), getInt(), getLong().

例如,如果我调用getInt(),它将返回4个字节作为字符串,并将char指针地址移动4.在哪里可以找到这些方法?

So for instance if i call getInt(), it will return the 4 bytes as a string and move the char pointer address by 4. Where can i find these methods?

推荐答案

由于指针运算属于C本质,所以类似Java的函数在那里不可用。

Since pointer arithmetic is in the very nature of C, such Java-like functions are not available there.

要得到 int ,你可以这样做:

To get an int out of some memory buffer you would do:

/* assuming that buf is of type void * */
int x = *((int *) buf);
/* advance to the position after the end of the int */
((int *) buf)++;

或更紧凑:

int x = *((int *) buf)++;

这篇关于在C / C ++中读取字节方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆