我有升壓轉換在Python到C一些二進制++ :: python.The二進制可能來自於圖像或文字file.But一些錯誤發生的圖像轉換文件的二進制文件轉換爲C++。以下是一個例子。關於Boost.Python的Python的二進制轉換成C++二進制A錯誤
C++
#include <boost/python.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <fstream>
#include <iostream>
using namespace boost::python;
void greet(char *name,char *ss)
{
std::ofstream fout(name,std::ios::binary);
std::cout<< "This length is:" << strlen(ss) <<std::endl;
fout.write(ss.strlen);
fout.close();
return;
}
BOOST_PYTHON_MODULE(ctopy)
{
def("greet",greet);
}
蟒蛇:
import ctopy
#It is right.
f=open("t1.txt","rb")
ctopy.greet("t2.txt",f.read())
f.close()
#Do a error.There isn't data in the file "p2.jpg".
f2=open("p1.jpg","rb")
ctopy.greet("p2.jpg",f2.read()) #error.the file "p2.jpg" will be a empty file.
f2.close()
如何圖像的二進制轉換爲C++?
你的問題根本不清楚,你正試圖完成什麼樣的**,發生了什麼錯誤?用所需信息編輯您的問題。 – StoryTeller 2013-02-11 14:55:57
@ StoryTeller,我寫了更多。它會在最後的python代碼中創建一個錯誤文件。 – simon 2013-02-11 15:15:41