Thousand separator with wide/unicode stream

Andrey Pro

May be the best way to describe, what I would like to achieve, is to combine solutions from following threads: Windows Unicode C++ Stream Output Failure (but with utf-16)

and

How to print a number with a space as thousand separator? (but with dot as separator)

The following solution attempts had no effect on output:

//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
}

also, since MVS/windows already uses UTF16 for wide strings, i wonder why a conversion to utf16 is necessary at all. As I see it, it is a waste of the CPU resources. Is it not possible to write file without the extra unnecessary conversion? writing in binary mode is possiblity, but kind of silly, because it would forfeit all conveniences output stream provide

EDIT: forgot to mention that I use MVS 2013 with Intel compiler

Igor Tandetnik

The second variant works, once you make do_grouping const, as in

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

As written, yours overloads, but doesn't override, the base class method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Thousand Separator in DBGrid

From Dev

Devexpress XRtableCell thousand separator?

From Dev

Thousand separator in awk

From Dev

validate decimal with decimal separator and thousand separator

From Dev

How to format number with "." as thousand separator, and "," as decimal separator?

From Dev

Set global thousand separator on knitr

From Dev

Regex valid numbers with thousand separator

From Dev

Format number with space as thousand separator

From Dev

Thousand separator not working right way

From Dev

Adding Thousand Separator to Int in Swift

From Dev

Remove thousand separator from string

From Dev

dot instead of comma as thousand separator

From Dev

Regex valid numbers with thousand separator

From Dev

Thousand separator not working right way

From Dev

Adding thousand separator to jQuery Counter

From Dev

Format number with space as thousand separator

From Dev

Adding Thousand Separator Automatically (Swift)

From Dev

String Number format with "/" for thousand separator

From Dev

d3.format thousand separator on variables?

From Dev

Formatting thousand separator for integers in a pandas dataframe

From Dev

Decimal not showing group(thousand) separator after parse

From Dev

regex for multiple formats decimals and thousand separator

From Dev

ExtJS 6 thousand separator in number field

From Dev

Is it possible to print a number formatted with thousand separator in Rust?

From Dev

Python replace middle digits with commas thousand separator

From Dev

Adding thousand separator while printing a number

From Dev

Regular expression for thousand separator without decimal point

From Dev

Format a bootstrap table with dollar sign and thousand separator

From Dev

Only add thousand separator before decimal comma

Related Related

  1. 1

    Thousand Separator in DBGrid

  2. 2

    Devexpress XRtableCell thousand separator?

  3. 3

    Thousand separator in awk

  4. 4

    validate decimal with decimal separator and thousand separator

  5. 5

    How to format number with "." as thousand separator, and "," as decimal separator?

  6. 6

    Set global thousand separator on knitr

  7. 7

    Regex valid numbers with thousand separator

  8. 8

    Format number with space as thousand separator

  9. 9

    Thousand separator not working right way

  10. 10

    Adding Thousand Separator to Int in Swift

  11. 11

    Remove thousand separator from string

  12. 12

    dot instead of comma as thousand separator

  13. 13

    Regex valid numbers with thousand separator

  14. 14

    Thousand separator not working right way

  15. 15

    Adding thousand separator to jQuery Counter

  16. 16

    Format number with space as thousand separator

  17. 17

    Adding Thousand Separator Automatically (Swift)

  18. 18

    String Number format with "/" for thousand separator

  19. 19

    d3.format thousand separator on variables?

  20. 20

    Formatting thousand separator for integers in a pandas dataframe

  21. 21

    Decimal not showing group(thousand) separator after parse

  22. 22

    regex for multiple formats decimals and thousand separator

  23. 23

    ExtJS 6 thousand separator in number field

  24. 24

    Is it possible to print a number formatted with thousand separator in Rust?

  25. 25

    Python replace middle digits with commas thousand separator

  26. 26

    Adding thousand separator while printing a number

  27. 27

    Regular expression for thousand separator without decimal point

  28. 28

    Format a bootstrap table with dollar sign and thousand separator

  29. 29

    Only add thousand separator before decimal comma

HotTag

Archive