I am trying to figure out a generic solution that can be used to align text to the left and right of a specified line width.
Note: the text can be in almost any international language, English, Japanese, Chinese etc.
i.e
std::wstring str1 = L"Hello1";
std::wstring str2 = L"Hello2";
std::cout << std::string(50, '-') << endl;
std::wcout << std::left << std::setw(25) << str1 << std::right << std::setw(25) << str2 << std::endl;
Produces the following:
--------------------------------------------------
Hello1 Hello2
The "----" line is 50 characters wide (ignoring the new line) and the two strings "Hello1" and "Hello2" are aligned to the left and right.
But The issue is with the following:
std::wstring str1 = L"Hello1";
std::wstring str2 = L"Hello2";
std::wstring str3 = L"こんにちは";
std::wstring str4 = L"你好";
std::cout << std::string(50, '-') << endl;
std::wcout << std::left << std::setw(25) << str1 << std::right << std::setw(25) << str2 << std::endl;
std::wcout << std::left << std::setw(25) << str3 << std::right << std::setw(25) << str4 << std::endl;
std::cout << std::left << std::setw(25) << "こんにちは" << std::right << std::setw(25) << "你好" << std::endl;
Which produces the following:
--------------------------------------------------
Hello1 Hello2
S�kao `}
こんにちは 你好
- I have tried to figure out a way to align the third row to the right without success, ideas?
- I do not understand why the second row is presented as "junk", any idea on how to fix this row without any major change?