Jump to content
  • Advertisement
Sign in to follow this  
FGFS

cast int to char*

This topic is 1324 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

I try:

 

        int    x, y;
        XPLMGetMouseLocation(&x, &y);
        XPLMDebugString((char*)x, (char*)y);

 

and get:

Multiple markers at this line
    - Invalid arguments ' Candidates are: void XPLMDebugString(const char
     *) '
    - cast to pointer from integer of different size [-Wint-to-pointer-cast]
    - too many arguments to function ‘void XPLMDebugString(const char*)’

 

Thanks

 

Share this post


Link to post
Share on other sites
Advertisement

Yes thanks. It works with snprintf on Ubuntu, I'll later compile it on Win/OSX.

Share this post


Link to post
Share on other sites

There are actually many forms of 'casting' - it's a broad term.

 

More specifically, you are wanting to convert an integer to a string, using some kind of int-to-string function. Since you are using C++, you can use std::to_string(), which gives you a std::string, and then get str.c_str() to get a c-style string pointer.

 

With many types, you can't just go 'varA = varB' and hope it works, because it might not do conversions, and instead might just reinterpret (a different form of casting).

 

 

[Edit:] Fixed the function name, thanks Buckeye! smile.png  

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!