0

Why is std::setw() considering special chars as two chars ? Is there any easy and stylish way to solve this ?

Eg :

#include <iostream>
#include <iomanip>

int main()
{
    std::cout << std::left << std::setw(10) << "ok" << "ok" << std::endl;
    std::cout << std::left << std::setw(10) << "test.." << "ok again" << std::endl;
    std::cout << std::left << std::setw(10) << "®èé" << "fail" << std::endl;

    return 0;
}

Ouputs :

ok        ok
test..    ok again
®èé    fail

Here is the live test : http://ideone.com/q57I0H

BoBTFish
  • 19,167
  • 3
  • 49
  • 76
user1527491
  • 895
  • 10
  • 22
  • Use std::wcout for wide characters output – Jaffa Feb 26 '14 at 11:36
  • I guess you are using utf8 encoding. there is a related bug in gcc. check here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33852. You can convert all your strings to wchar_t, and use wcout. – SHR Feb 26 '14 at 11:58

1 Answers1

0

They are two characters, check the value of sizeof("®èé")

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521