# std::numpunct<CharT>::thousands_sep, do_thousands_sep

> C++ Atlas: `cppatlas.com/w/cpp/locale/numpunct/thousands_sep` | Source: https://en.cppreference.com/w/cpp/locale/numpunct/thousands_sep | Domain: Localization

The object of type char_type to use as the thousands separator. The standard specializations of std::numpunct return ',' and L','.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <locale>

public:
char_type thousands_sep() const; // (1)

protected:
virtual char_type do_thousands_sep() const; // (2)
```

1) Public member function, calls the member function `do_thousands_sep` of the most derived class.

2) Returns the character to be used as the separator between digit groups when parsing or formatting integers and integral parts of floating-point values.

### Return value

The object of type `char_type` to use as the thousands separator. The standard specializations of `std::numpunct` return `','` and `L','`.

### Example

```cpp
#include <iostream>
#include <locale>

struct space_out : std::numpunct<char>
{
    char do_thousands_sep()   const { return ' '; }  // separate with spaces
    std::string do_grouping() const { return "\1"; } // groups of 1 digit
};

int main()
{
    std::cout << "default locale: " << 12345678 << '\n';
    std::cout.imbue(std::locale(std::cout.getloc(), new space_out));
    std::cout << "locale with modified numpunct: " << 12345678 << '\n';
}
```

Output:

```text
default locale: 12345678
locale with modified numpunct: 1 2 3 4 5 6 7 8
```

### Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

| DR | Applied to | Behavior as published | Correct behavior |
| --- | --- | --- | --- |
| LWG 20 | C++98 | the return type was `string_type` | changed to `char_type` |

### See also

- [`do_grouping`](https://en.cppreference.com/w/cpp/locale/numpunct/grouping) [virtual]: provides the numbers of digits between each pair of thousands separators (virtual protected member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/locale/numpunct/thousands_sep (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.