2014-05-25 8 views
0

내가 달성하고 싶은 무엇을 설명하는 가장 좋은 방법이 될 수 있습니다, 다음 스레드에서 솔루션을 결합하는 것입니다천 분리

//include appropriate headers 

struct DotSepUTF16 : public codecvt_utf16<wchar_t, 0x10ffffUL, little_endian> 
{ 
    wchar_t do_thousands_sep()const{ return L'.'; } 
    string do_grouping(){ return "\3"; } 
}; 
int main() 
{ 
unsigned long num=135412565UL; 
locale dot_separated(locale(), new DotSepUTF16); 
wofstream fout(L"C:\\Work\\report.htm"); 
fout.imbue(dot_separated); 
const unsigned short BOM= 0xFEFF; 
fout.write((wchar_t*)&BOM, 1); 
fout<<num;//still no separation 
} 

//second attempt 

struct DotSep : public numpunct <wchar_t> 
{ 
    wchar_t do_thousands_sep()const{ return L'.'; } 
    string do_grouping(){ return "\3"; } 
}; 

int main(void) 
{ 
unsigned long num=135412565UL; 
locale utf16(locale(), new codecvt_utf16<wchar_t, 0x10ffffUL, little_endian>()); 
locale dot_separated(locale(), new DotSep); 
locale mylocale(utf16, dot_separated, locale::numeric);//try to combine the locales for utf16 and dot separation 
wofstream fout(L"C:\\Work\\report.htm"); 
fout.imbue(mylocale); 
const unsigned short BOM= 0xFEFF; 
fout.write((wchar_t*)&BOM, 1); 
fout<<num; //again no dots 
} 
012,341,462 :

How to print a number with a space as thousand separator? (그러나 세퍼레이터로서 도트)

다음 용액 시도는 출력에 영향을 미치지 않았다또한 MVS/windows는 이미 넓은 문자열에 대해 UTF16을 사용하기 때문에 utf16으로의 변환이 왜 필요한지 궁금합니다. 내가보기에는 CPU 자원 낭비입니다. 불필요한 변환없이 파일을 쓸 수 있습니까? 바이너리 모드로 작성하는 것이 모든 편의 출력 스트림이

편집을 제공 상실 때문에, 종류의 바보 possiblity를, 그러나 : 당신이 만드는 일단 내가 인텔 컴파일러와 MVS 2013 사용을 언급하는 것을 잊었다

답변

1

두 번째 변형, 작동 do_groupingconst 서면, 당신은 오버로드하지만, 기본 클래스의 메소드를 오버라이드 (override)하지 않는 것처럼

string do_grouping() const { return "\3"; } 

에있다.