我正在开展一个小项目并遇到以下情况:
std::string myString;
#GetValue() returns a char*
myString = myObject.GetValue();
Run Code Online (Sandbox Code Playgroud)
我的问题是如果GetValue() 返回NULL myString变为空字符串?这是不确定的?还是会发生段错?
这是完整的情况:我正在.tmx使用瓷砖的地图阅读器处理文件.大多数时候,tile都保存在一个base64字符串中,该字符串包含一个压缩的字节数组gzip.现在我可以读取压缩字节数组,但我不知道如何解压缩它.我读了一些关于zlib和的文档boost,但两者都是关于文件流而且非常复杂......
我对数据压缩领域很陌生,所以如果有人知道某种解决方案或一些有用的文档,我真的很感兴趣.
我正在用SDL编写一个小游戏,文件的结构如下:
"src/game /"同时包含.h和.cpp源文件.
"data /"有游戏文件,如地图,tilesets,sprite等......
例如,我将使用以下代码加载精灵.
spriteLib.loadSprite("data/sprites/sprite-ghost.bmp");
Run Code Online (Sandbox Code Playgroud)
要将此字符串转换为绝对路径,我在函数的前4行中包含这些行:
SSprite CSpriteLib::loadSprite(std::string file)
{
//Converting the file path
char converted[128];
realpath(file.c_str(),converted);
file = converted;
Run Code Online (Sandbox Code Playgroud)
但是这样程序只能在liux下编译...所以如果有人知道另一种方法,我会很感激.
我正在尝试从boost文档中编译这段代码:(http://www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/tutorial/filter_usage.html)
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/filtering_stream.hpp>
namespace io = boost::iostreams;
int main()
{
io::filtering_ostream out;
out.push(compressor());
out.push(base64_encoder());
out.push(file_sink("my_file.txt"));
// write to out using std::ostream interface
}
Run Code Online (Sandbox Code Playgroud)
但它拒绝编译,我得到以下错误:
克++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/USR /共享/ QT4/mkspecs/Linux的克++ -I ../泰斯特-I的/ usr /包括/ QT4/QtCore - I/usr/include/qt4/QtGui -I/usr/include/qt4 -I.-I ../ teste -I.-o main.o ../teste/main.cpp
../teste/main.cpp:在函数'int main()'中:
../teste/main.cpp:9:25:错误:'compress'未在此范围内声明
../teste/main.cpp:10:29:错误:'base64_encoder'未在此范围内声明
../teste/main.cpp:11:37:错误:'file_sink'未在此范围内声明
我知道我可能做了一些愚蠢的事情,但我看不出是什么......
编辑:
顺便说一句,我已经正确安装了库和-dev文件.我正在使用QT-Creator,所以我的.pro文件看起来像这样:
SOURCES += \
main.cpp
LIBS += \
-lboost_filesystem \
-lboost_iostreams
Run Code Online (Sandbox Code Playgroud) c++ ×4
boost ×1
compression ×1
gzip ×1
inflate ×1
linker ×1
linux ×1
qt-creator ×1
sdl ×1
string ×1