태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

std::string 의 formating

2009/09/15 15:34

boost 라이브러리를 쓰라는 얘기도 있지만 일단.

#include <stdarg.h>

std::string format_arg_list(const char *fmt, va_list args)
{
    if (!fmt) return "";
    int   result = -1, length = 256;
    char *buffer = 0;
    while (result == -1)
    {
        if (buffer) delete [] buffer;
        buffer = new char [length + 1];
        memset(buffer, 0, length + 1);
        result = vsnprintf(buffer, length, fmt, args);
        length *= 2;
    }
    std::string s(buffer);
    delete [] buffer;
    return s;
}
 
std::string format(const char *fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    std::string s = format_arg_list(fmt, args);
    va_end(args);
    return s;
}

참고 -  http://bluenlive.net/494


추가 - 피보기 전에 이 글도 확인을
http://blog.yurihan.net/entry/stdstring%EC%9D%98-formating-%EC%8B%9C%EB%B0%9C-%EB%82%9A%EC%98%80%EB%8B%A4
크리에이티브 커먼즈 라이선스
Creative Commons License

유리한 코드창고

  1. 만약 gcc에서 해당 코드를 돌리려는 생각이라면
    http://blog.yurihan.net/entry/stdstring%EC%9D%98-formating-%EC%8B%9C%EB%B0%9C-%EB%82%9A%EC%98%80%EB%8B%A4
    를 참고하라. 못보고 눈물 쏟지 않도록.

  2. Blog Icon
    Formal Dresses

    Couldn't be written any better. Reading this post reminds me of my old room mate! He always kept talking about this <a href="http://www.dressaler.com/shoes.html" title="wedding shoes">wedding shoes</a>. This way even more people can enjoy your posts <a href="http://www.dressaler.com/wedding-accessories.html" title="Cheap Wedding Accessories">Cheap Wedding Accessories</a> and nothing beats a big audiance ;).I’m very certain they will understand lots of new stuff here than anybody else. I do appreciate that youve added relevant and intelligent commentary here though.<a href="http://www.dressaler.com/special-sale-wedding-dress-in-stock.html" title="wedding dress on sale">wedding dress on sale</a> Thank you!