Possible Duplicate:
convert a file (.txt,.pdf..) into a stream file
std::string fil= "/home/sensor.pdf";
std::ifstream t(fil.c_str());
if (t)
{
string res;
string line;
while (getline(t, line, '\n'))
{
res=res+line;
}
std::string p;
p=(((reinterpret_cast<const unsigned char *> (res.c_str())),res.size()));
std::string f_data=p;
char *token = strtok( const_cast<char*>(fil.c_str() ), "/" );
std::string name;
std::vector<int> values;
while ( token != NULL )
{
name=token;
token = strtok( NULL, "/" );
}
std::strig f_name=name;
}
When I try to load the .pdf file I have an error "unable to read. PDF IS DAMAGED". WHY? This code works for .txt files and .cpp files. I've tested it. I am currently working in ubuntu c++ code. I've also used the base_64 encode/decode because this was the request.