Can I use c_str() in cocos2dx?

  • igorppbr
    Likes 0

    Problem Description

    Hello,

    I trying to use c_str() in a string in cocos2dx.

    In Sprite::Create() and in CCLOG() I can pass a const char value. I have a string and Im trying to get the const char value to pass in these methods, but I trying to use c_str() and not work.

    I tested this:

        std::string _test("sprite1.png");
        const char _char = _test.c_str();
        CCLOG("my test %s",_char);

    But I get: “error: invalid conversion from 'const char*' to 'char' [-fpermissive]

    How I can get the const char value?

     

  • Sonar Systems admin
    Likes 0

    Why are you using a const char?

  • igorppbr
    Likes 0

    In CCLOG and in Sprite::Create I have to use a const char, or not?

    I have a std::string and I need to use the string value in these methods.

  • Sonar Systems admin
    Likes 1

    No, use a cocos2d::__String


    This reply has been verified.

Login to reply