티스토리 뷰

방법1)

to_string() 이용

#include <string>을 해줘야한다.

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int s = 5;

    string a = to_string(s);

    cout << a << "\n";
}

방법2)

stringstream이용

#include <sstream>을 해줘야한다.

#include <iostream>
#include <sstream>
using namespace std;

int main()
{
    int s = 5;
    stringstream ssint;

    ssint << s;

    cout << ssint.str() << "\n";
}

'프로그래밍 > C,C++' 카테고리의 다른 글

vector C++ STL(Standard Template Library)  (0) 2022.07.09
C/C++ 크리스마스 트리  (0) 2022.06.15
int main(int argc, char* argv[])  (0) 2019.09.14
문자열 인코딩 개념정리  (0) 2019.09.14
C++ 라이브러리 추가 전처리기  (0) 2019.07.29
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/10   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함