简体   繁体   中英

How to read ifstream from unsigned char?

I have unsigned char like below.

unsigned char out[CHUNK];

Which is decompressed by zlib.

I need ifstream to read from that unsigned char without saving into temp files.

ifstream file;

What options do I have?

Instead of ifstream, you need stringstream. You can use it as follows:

#include <sstream>
stringstream file(out);

int value;
file >> value;

The documentation of stringstream is available at: http://www.cplusplus.com/reference/sstream/stringstream/stringstream/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM