Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ RLE:由两个符号编码_C++_Run Length Encoding - Fatal编程技术网

C++ RLE:由两个符号编码

C++ RLE:由两个符号编码,c++,run-length-encoding,C++,Run Length Encoding,我创建了RLE编码函数,它将类似“A1A1B7B7”的序列编码为这样的字符串:“A12”B74 void编码(常量字符*输入路径,常量字符*输出路径) {//SBDLib::sbimak::encode的开头 std::fstream输入(输入路径,std::ios_base::in | std::ios_base::binary); std::fstream输出(输出路径,std::ios_base::out | std::ios_base::binary); int size=0;//设置大

我创建了RLE编码函数,它将类似“A1A1B7B7”的序列编码为这样的字符串:“A12”B74

void编码(常量字符*输入路径,常量字符*输出路径)
{//SBDLib::sbimak::encode的开头
std::fstream输入(输入路径,std::ios_base::in | std::ios_base::binary);
std::fstream输出(输出路径,std::ios_base::out | std::ios_base::binary);
int size=0;//设置大小变量
input.seekg(0,std::ios::end);//移动到EOF
size=input.tellg();//告诉位置
input.seekg(0);//移到开头
int i=1;//创建编码计数器
int counter=0;//创建颜色计数器
int cbyte1,cbyte2;//创建当前颜色字节
int-pbyte1=0x0;int-pbyte2=0x0;//创建以前的颜色字节
而(((cbyte1=input.get())!=EOF&&(cbyte2=input.get())!=EOF)
||input.tellg()>=大小)
{//while的开始
//如果当前字节不等于以前的字节
//或者光标位于输入文件的末尾,write
//将二进制数据写入文件;如果以前的字节
//未从0x0设置为任何其他整数。
如果((cbyte1!=pbyte1 | | cbyte2!=pbyte2)
||(input.tellg()=大小))
&&(pbyte1!=0x0&&pbyte2!=0x0))
{//主if的开始

输出根据从文件中读取的数据大小,最好不要一次读取单个字符,而是从输入文件中读取一大块数据。这可能比为每个输入字符访问磁盘上的输入文件快得多

伪代码示例:

char dataArray[100];

while( !EOF )
{
  input.get( &dataArray[0], 100 ); // read a block of data not a single charater

  process( dataArray ); // process one line
}

我必须阅读大文本文件;平均重量约为15 MiB。请您提供一个读取块的示例代码,我不明白您的意思。然后指定一次读取的字符的合理大小。查看文档
char dataArray[100];

while( !EOF )
{
  input.get( &dataArray[0], 100 ); // read a block of data not a single charater

  process( dataArray ); // process one line
}