기타
int 형에서 string 형으로 변환(error C2668 해결), int<->CString
이야기하는 남자
2022. 1. 10. 23:20
728x90
int 형에서 string 형으로 변환(error C2668 해결), int<->CString
이 포스트는 이전 블로그에서 이전된 포스트입니다.
아래와 같은 방법으로 변환이 가능합니다.
1
2
|
int num = 1;
string str_tmp = to_string(num);
|
cs |
단, 위 코드를 이용시 VC11이전 버전은 에러를 출력하는 버그를 가지고 있다고 합니다.
그 경우 아래와 같이 사용
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include <sstream>
#include <iostream>
string intToString(int n);
void main()
{
std::string s = intToString(1234);
std::cout << s;
}
string intToString(int n)
{
stringstream s;
s << n;
return ss.str()
}
|
cs |
추가
CString -> int : int형 = _ttoi(CString형)
int -> CString : CString형.Format(_T("%d"),int형);
추가 부분이 순서가 바뀌어 수정되었습니다.
728x90