편집 기록

편집 기록
  • 프로필 정토드님의 편집
    날짜2016.02.03

    정수형을 문자열로 변환할 때의 차이점


    정수형을 문자열로 바꾸는 방법엔 흔히 알기로 itoa()함수를 사용합니다.

    최근에 찾아본 #include 를 따르면,

    string convertInt(int number)
    {
       stringstream ss;//create a stringstream
       ss << number;//add number to the stream
       return ss.str();//return a string with the contents of the stream
    }
    

    위와 같은 방식으로 int <-> string 변환을 하게 되는데, itoa()를 사용 하는 것보다 간편하다고 느껴집니다.

    성능 면에서 itoa() 와 stringstream을 사용 하는 것, 둘 중 어느 것이 더 좋고 그 이유가 뭔가요?