简体   繁体   English

创建一个4字节的字符?

[英]Create a 4 byte Char?

I want to extract character data from a file and it must be directly convertable to a 4 byte int. 我想从文件中提取字符数据,它必须可以直接转换为4字节的整数。 Would anyone know how to convert a 1 byte char into a 4 byte char? 有谁知道如何将1字节char转换为4字节char?

Background: 背景:

I'm extracting stream data from a PDF file. 我正在从PDF文件中提取流数据。 That data is only encoded in LZW encoding. 该数据仅以LZW编码进行编码。 When extracting the data, if I use a char (this is before the decoding part), the maximum integer value the data will provide is 255, for obvious reasons (1 byte char, max 256). 提取数据时,如果我使用char(在解码部分之前),则出于显而易见的原因,数据将提供的最大整数值为255(1字节char,最大256)。 If I could extract the data straight into an integer without an intermediate char to catch the data (like my example below) it would probably get past this problem and display the correct numerical values (akin to LZW compressed data) which are in excess of 255. 如果我可以直接将数据提取为没有中间字符的整数来捕获数据(如下面的示例),则可能会克服此问题并显示超过255的正确数值(类似于LZW压缩数据) 。

Basically I want to be able to do this. 基本上我希望能够做到这一点。

char FourBiteChar; // I can't use the char data type, not sure how else to do this?
int MyInteger;

while (input >> FourBiteChar)
{
    MyInteger = FourBiteChar;
    MyVector.push_back(MyInteger);
}

you are probably looking for std::stringsteam 您可能正在寻找std::stringsteam

std::string tempstr;
int MyInteger;

while (getline(input, tempstr))
{
    std::stringstream tempss(tempstr);
    tempss >> MyInteger;
}

as for the fact that your file is not ASCII, but binary (pdf) you might want to check these answers: Reading text from binary file like PDF 至于您的文件不是ASCII而是二进制(pdf)的事实,您可能需要检查以下答案: 从二进制文件(如PDF)读取文本

C++ Reading a PDF file C ++读取PDF档案

Is there a C++ library to extract text from a PDF file like PDFBox for Java? 是否有C ++库从PDF文件(如Java的PDFBox)中提取文本?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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