加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d-x 控制台输出日志,不要CCLog

发布时间:2020-12-14 20:38:58 所属栏目:百科 来源:网络整理
导读:在2dx中用CCLog输出日志,但是在vs的控制台中由于信息很多,很难发现。可以用下面方法,会重新启动一个黑色的控制台来输出日志 修改main.c文件,如下: [cpp] view plain copy #include"main.h" #include"AppDelegate.h" #include"CCEGLView.h" #include"net

在2dx中用CCLog输出日志,但是在vs的控制台中由于信息很多,很难发现。可以用下面方法,会重新启动一个黑色的控制台来输出日志

修改main.c文件,如下:

[cpp] view plain copy
  1. #include"main.h"
  2. #include"AppDelegate.h"
  3. #include"CCEGLView.h"
  4. #include"net/NetWork.h"
  5. #include"adapter/RouterAdapter.h"
  6. USING_NS_CC;
  7. #defineUSE_WIN32_CONSOLE
  8. intAPIENTRY_tWinMain(HINSTANCEhInstance,
  9. HINSTANCEhPrevInstance,
  10. LPTSTRlpCmdLine,87); background-color:inherit; font-weight:bold">intnCmdShow)
  11. {
  12. UNREFERENCED_PARAMETER(hPrevInstance);
  13. UNREFERENCED_PARAMETER(lpCmdLine);
  14. #ifdefUSE_WIN32_CONSOLE
  15. AllocConsole();
  16. freopen("CONIN$","r",stdin);
  17. freopen("CONOUT$","w",stdout);
  18. freopen("CONOUT$",stderr);
  19. #endif
  20. //createtheapplicationinstance
  21. CCEGLView*eglView=CCEGLView::sharedOpenGLView();
  22. eglView->setViewName("MT");
  23. //eglView->setFrameSize(480,320);
  24. returnCCApplication::sharedApplication()->run();
  25. FreeConsole();
  26. #endif
  27. }

注意宏定义: #defineUSE_WIN32_CONSOLE 要加上这一句,否则在编译android文件的时候会编译出错,要想在控制台上输出中文,要用printf函数,否则会使乱码。

同时要注意 命名空间的引用,否则printf函数不能使用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读