본문 바로가기
전체보기/C&C++

int 형을 string 으로, integer to string c++

by 피망우유 2019. 11. 14.

Colored By Color Scripter

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

#include <iostream>

#include <sstream>

#include <string>

 

using namespace std;

 

int main(){

 

    int cnt = 0;

    string s;

    string num;

 

    while(cnt < 5) {

 

        stringstream sstr;

        s = "name";

 

        sstr<<cnt;

        num = sstr.str();   // int 형을 string 형으로 변환

 

        s = s + num;

 

        cout<<s<<'\n';        // 결과 확인

 

        cnt++;

 

    }

 

    return 0;

}

>> 실행 결과

 

 

 

?? 네이버에 붙여넣으면 이쁘게 되던데 티스토리는 왜;;

'전체보기 > C&C++' 카테고리의 다른 글

find_red.cpp  (0) 2019.11.22
VS2017 (성가신) 에러  (0) 2019.11.14
VS2017 단축키 변경  (0) 2019.11.14

댓글