getline 在不同编译器的表现,对换行符的处理

来源:互联网 发布:怎么制作mac安装u盘 编辑:程序博客网 时间:2024/06/05 03:21

在移植Lives2D的过程中,又碰到了问题。

Lives2D的序列帧动画 ImageAnimation 是通过读取txt配置文件来读取序列帧文件名的,一个配置文件可能如下:

Idle:frame_0.png,frame_1.png,frame_2.png,frame_3.png,frame_4.png,frame_5.pngTalk:frame_6.png,frame_7.png,frame_8.png,frame_9.png,frame_10.png,frame_11.png

在PC上一切正常,但是在Android上出现了问题,FreeImage读取Idle的 frame_5.png 这个图片的时候读取不出来。

在打Log调试后,错误提示文件不存在。

从Logcat中拷贝Log出来查看才发现 frame_5.png后面带了换行符。

转自http://www.liveslives.com/ http://blog.csdn.net/huutu

在VS的编译器是没有问题的,但是NDK的GCC却读入了换行符。

只好针对处理了。

while (getline(infile, s)){size_t pos = s.find('\n');if (pos!=string::npos){s.erase(pos, 1);}pos = s.find('\r');if (pos != string::npos){s.erase(pos, 1);}}