我试图用Python的zlib的输出输出到C++字符串。这里的问题与Python zlib output, how to recover out of mysql utf-8 table?非常相似,不同之处在于我的python脚本生成一个C++头文件,其中压缩数据应该以字符串形式存储。但是,由于特殊字符和原始字节,我无法让C++将其作为字符串读取。之所以我不能将它写入文件,然后返回到C++程序,是因为这可能是一个驱动程序组件,因此不允许读取文件。 这是我正在尝试的一个小例子。蟒蛇zlib的输出到C++字符串
compressed_string = zlib.compress("This is a huge string. Around 263KB")
fptr = open('my_header.h', 'w')
content = "#ifndef __HEADER_DEFS__\n\
#define __HEADER_DEFS__\n\
\n\
#include \n\
\n\
std::string binary_compressed = \"%s\" \n\
\n\
#endif" % compressed_string
fptr.write(content)
fptr.close()
不过,我压缩串是一个巨大的数据,不像比如我在这里给出的,因此我增加了屏幕截图的那种,我在实际的例子越来越字符。
请看一看http://tinypic.com/r/1078lxw/7的屏幕截图。 谢谢
注意'\'仍还可印刷将引起当由C/C++编译器解析逸出。 – 2011-03-15 15:38:12
@Mark B thx固定 – Will 2011-03-15 16:32:32
非常感谢。该工程 – ssarangi 2011-03-16 14:20:46