1. 스트림의 형식화를 위한 manipulator는 ipmanip에 정의되어 있다.
2. stringstream을 문자열을 형식화 하기 위한 출력스트림으로 이용하고 str()멤버를 통해서 string을 얻어서 사용할 수 있다.
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <atlbase.h>
using namespace std;
void makeFileName (const CComBSTR &bstrPath, const CComBSTR &bstrPrefix)
{
wstringstream fname;
wstring wstrIndexFileName, wstrDataFileName;
fname << (BSTR)bstrPath << L"\\" << (BSTR)bstrPrefix << setfill(L'0')
<< L"_" << setw(4) << (int)2005 << setw(2)
<< (int)1 << setw(2) << (int)1
<< L"_" << setw(4) << (int)2005 << setw(2)
<< (int)12 << setw(2) << (int)31
<< L"_" << setw(4) << (int)1;
// setw와 setfill로 너비와 채움문자를 설정해서 날짜값을 형식화 한다.
wstrIndexFileName = fname.str() + L".log";
wstrDataFileName = fname.str() + L".dat";
// 문자열에 대한 + operator 테스트.
wprintf(L"IndexFileName : %s\n", wstrIndexFileName.c_str());
wprintf(L"DataFileName : %s\n", wstrDataFileName.c_str());
}
void main(void)
{
makeFileName(L"C:\\temp", L"MessageLog");
// CComBSTR의 임시객체가 생성되에서 makeFileName에 전달된다.
}
=============== Output =================
IndexFileName : C:\temp\MessageLog_20050101_20051231_0001.log
DataFileName : C:\temp\MessageLog_20050101_20051231_0001.dat
출처:http://manylee.tistory.com/49?srchid=BR1http%3A%2F%2Fmanylee.tistory.com%2F49
'내밥줄 > 프로그래밍' 카테고리의 다른 글
[펌]실행에 필요한 동적라이브러리 확인하기 (0) | 2009.04.23 |
---|---|
[펌][Linux] Vim & Cscope (0) | 2009.03.30 |
[펌]Windows XP + Cygwin으로 iphone, ipod touch 개발환경 한방에 설치 (0) | 2009.03.17 |
[펌]gdb 를 통한 디버깅 따라하기 (0) | 2009.02.16 |
[펌] variadic macro __VA_ARGS__ 를 이용한 간단한 로그 매크로 (0) | 2009.01.29 |