先上代码
#include <iostream>
#include <string>
void testFormat() {
printf("%3d\n", 1);
printf("%3d\n", 11);
printf("%3d\n", 111);
printf("%03d\n", 1);
printf("%03X\n", 10);
}
void testEquals(const std::string& in_oStr) {
if ("123" == in_oStr) {
printf("\"123\" == in_oStr");
}
}
int main() {
testFormat();
testEquals("123");
return 0;
}
//1
//11
//111
//001
//00A
//"123" == in_oStr
一、关于 testFormat 函数
在 cocos2d 拼接动画名称还是挺实用的, 之前因为基础不牢固,
对于美术出的动画序列,walk_001.png, walk_002.png, ..., walk_013.png
我还得重新造轮子,写一些判断逻辑去填补高位的 0,实在是有损作为一名程序的颜面啊...
二、关于 testEquals 函数
之前不知道 std::string 还可以这么去判断字符串是否相等,
一直都是采用 !strcmp("123", in_oStr.c_str()) 的方式来判断,想想真挺蛋疼的
不过目前对这种写法的安全性还有一些怀疑,需要进一步验证一番后才敢 “大规模使用”