COCOS2DX Study Notes (2) string char* int type data conversion

Source: Internet
Author: User


1, char* turn string

char* cp = "char"; std::string SP = CP;


2. String Turn char*

1std::string str = "string"; const char* CP = Str.data ();//2std::string str = "string"; const char* CP = STR.C_STR ();//3st d::string str = "Hello"; char p[10];str.copy (P, 4, 1);//Here 4, which represents a copy of several characters, 1 represents the starting position of the copy index* (p + 4) = ' + '; To manually add a terminator


3, int turn string

int number = 32;char temp[10];sprintf (temp, "%d", number, ten); std::string s = temp;


4. Cocos2d proprietary Conversion method

int index = 100;std::string str = value (index). asstring (); int index2 = value (str). Asint ();



This article is from the "Grape Sweet vinegar" blog, please be sure to keep this source http://putaotiancu.blog.51cto.com/8627957/1599390

COCOS2DX Study Notes (2) string char* int type data conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.