从文件中无符号的字符数组读取文本,错误,同时试图使用例子 [英] Reading text from file to unsigned char array, errors while trying to use example

查看:215
本文介绍了从文件中无符号的字符数组读取文本,错误,同时试图使用例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用从例如:

http://stackoverflow.com/a/6832677/1816083
但我有:

 从`无符号字符*'到'字符*'无效的转换
初始化的`的std :: basic_istream&LT参数1; _CharT,_Traits>&安培;的std :: basic_istream< _CharT,_Traits> ::阅读(_CharT *,性病:: streamsize可)与_CharT =字符,_Traits =的std :: char_traits<烧焦>]
从`无效*'到'为size_t无效的转换

在行:

 为size_t bytes_read缓存= myfile.read((无符号字符*)缓冲区,BUFFER_SIZE);


解决方案

首先,阅读()需要的char * 而非无符号字符* 。其次,它不返回读的字符数。

相反,尝试:

  myfile.read((字符*)缓冲区,BUFFER_SIZE);
的std :: streamsize可bytes_read缓存= myfile.gcount();

I'm trying to use example from:

http://stackoverflow.com/a/6832677/1816083 but i have:

invalid conversion from `unsigned char*' to `char*'
initializing argument 1 of `std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::read(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]' 
invalid conversion from `void*' to `size_t'

in line:

size_t bytes_read = myfile.read((unsigned char *) buffer, BUFFER_SIZE);

解决方案

Firstly, read() takes a char* rather than unsigned char*. Secondly, it does not return the number of characters read.

Instead, try:

myfile.read((char*)buffer, BUFFER_SIZE);
std::streamsize bytes_read = myfile.gcount();

这篇关于从文件中无符号的字符数组读取文本,错误,同时试图使用例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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