Reputation: 566
I want to extract character data from a file and it must be directly convertable to a 4 byte int. Would anyone know how to convert a 1 byte char into a 4 byte char?
Background:
I'm extracting stream data from a PDF file. That data is only encoded in LZW encoding. 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). 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.
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);
}
Upvotes: 1
Views: 406
Reputation: 1090
you are probably looking for 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
Is there a C++ library to extract text from a PDF file like PDFBox for Java?
Upvotes: 2