mystic-agit 개발 블로그

C++ 변수 타입 형 변환 본문

Cocos2d-x

C++ 변수 타입 형 변환

mystic-agit 2023. 4. 18. 12:45

Cocos2d-x 프로젝트 관리 중 주로 사용했던 형 변환 방법을 기록해두었다.

 

#include <stdio.h>

using namespace std;

void TestClass::myTest() {

	// int to bool
    bool value1 = bool(1);
    
    // bool to int
    int value2 = int(true);
    
    // int to string
    string value3 = to_string(123456);
    
    // string to int
    int value4= stoi("123456");
    
    // int to double
    double value5 = static_cast<double>(123);
    
    // double to int
    int value6 = (int)(value5);
    // 단, 소수점이하 값이 있는 double일 경우 반올림 여부는 round 등 함수를 통해 별도로 해결 필요
    
}
Comments