string이랑 int를 붙이고 싶어요

조회수 2580회

쉬울줄 알았는데 어렵네요 ㅜㅜㅜ 아래 코드에서 string name"John21"이 되게 하려면 어떻게 해야할까요

소스코드

string name = "John";
int age = 21;

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    알파벳 순서대로 적겠습니다.

    사용법


    // 1. Boost result = name + boost::lexical_cast<std::string>(age).

    // 2. FastFormat.Format fastformat::fmt(result, "{0}{1}", name, age);

    // 3. FastFormat.Write fastformat::write(result, name, age);

    // 4. IOStreams std::stringstream sstm; sstm << name << age; result = sstm.str();

    // 5. itoa char numstr[21]; // enough to hold all numbers up to 64-bits result = name + itoa(age, numstr, 10);

    // 6. sprintf char numstr[21]; // enough to hold all numbers up to 64-bits sprintf(numstr, "%d", age); result = name + numstr;

    // 7. STLSoft's integer_to_string char numstr[21]; // enough to hold all numbers up to 64-bits result = name + stlsoft::integer_to_string(numstr, 21, age);

    // 8. STLSoft's winstl::int_to_string() result = name + winstl::int_to_string(age);

    // 9. Poco NumberFormatter result = name + Poco::NumberFormatter().format(age);

    설명


    1. 안전하고 느린방법. Boost헤더가 필요함. 모든 플랫폼에서 동작
    2. 안전하고 빠른방법. FastFormat이 필요함. 모든 플랫폼에서 동작
    3. 안전하고 빠른방법. FastFormat이 필요함. 모든 플랫폼에서 동작
    4. 안전하고 느린방법. #include 해야. 은 c++ standard이므로 모든 플랫폼에서 동작
    5. 불안하고 빠른방법. 큰 버퍼가 필요, itoa()는 standard가 아니기 때문에 모든 플랫폼에서 동작할거란 보장이 없음
    6. 불안하고 빠른방법. 큰 버퍼가 필요, c++ standard이므로 모든 플랫폼에서 동작.
    7. 불안하고 가장빠른방법. 큰 버퍼가 필요, STLSoft가 필요함. 모든 플랫폼에서 동작
    8. 가장안전하고 빠른 방법. STLSoft가 필요함. 윈도우에서만 동작
    9. 안전하고 느린방법. Poco C++이 필요. 모든 플랫폼에서 동작

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)