「Cocos2dx/Log」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→ログカスタム関数) |
(→ログカスタム関数) |
||
| 行19: | 行19: | ||
==ログカスタム関数== | ==ログカスタム関数== | ||
int cnt = 10; | int cnt = 10; | ||
| + | const char* chr = "a"; | ||
addLog("init"); | addLog("init"); | ||
addLog("id=" + label->getString()); | addLog("id=" + label->getString()); | ||
| − | addLog("count=" + StringUtils::toString(cnt)); | + | addLog("count=" + StringUtils::toString(cnt)); // int |
| + | addLog("log=" + std::string(chr); // char | ||
void HelloWorld::addLog(const std::string str) { | void HelloWorld::addLog(const std::string str) { | ||
log("%s", str.c_str()); | log("%s", str.c_str()); | ||
} | } | ||
2018年9月25日 (火) 14:25時点における版
目次
サンプル
log("hoge");
int _int = 1;
log("%i", _int);
const char *str = "hogestr";
log("%s", str);
double _double = 1.0001;
log("%f", _double); // 1.000100;
android studioで確認した場合
02-20 16:59:52.260 18958-18981/com.example.helloworld D/cocos2d-x debug info: hoge
error: cannot convert 'const char*' to 'double' for argument '1' to 'double log(double)'エラーとなる場合
以下を記述するか
USING_NS_CC;
coocs2d::を追加する
cocos2d::log("hoge");
ログカスタム関数
int cnt = 10;
const char* chr = "a";
addLog("init");
addLog("id=" + label->getString());
addLog("count=" + StringUtils::toString(cnt)); // int
addLog("log=" + std::string(chr); // char
void HelloWorld::addLog(const std::string str) {
log("%s", str.c_str());
}
