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;
}
当我尝试加载.pdf文件时,出现错误“无法读取.PDF已损坏”。为什么?此代码适用于.txt文件和.cpp文件。我测试过了。我目前正在使用ubuntu c ++代码。我还使用了base_64编码/解码,因为这是请求。
答案 0 :(得分:3)
试试这个:http://sourceforge.net/projects/libharu/
我看到它在几个不同的地方推荐,包括几个不同的SO问题 - 但他们给的只是链接。
这是一个免费的,开源的PDF阅读库。它可能并不像你想要的那么容易,但我认为它就像你要获得的那样简单而且是免费的。
它也是多平台的,所以应该在UNIX和Windows上工作。
答案 1 :(得分:0)
尝试打开:
ifstream file ("/home/sensor.pdf", ios::in|ios::binary);