So I've already found How to capitalize a word in a C++ string? , but I've tried similar code as has been suggested, including what's provided in the examples for Boost::locale. I'll also include what my code is currently and what the expected and real output are. So I'm trying to understand why I'm not getting the expected output.
#include <iostream>
#include <string>
#include <boost/locale.hpp>
#include <boost/algorithm/string/case_conv.hpp>
int main() {
using namespace std;
using namespace boost::locale;
generator gen;
auto loc = gen("");
locale::global(loc);
cout.imbue(loc);
ios_base::sync_with_stdio(false);
cout << to_upper("hello!") << " " << boost::to_upper_copy("hello!"s) << endl;
cout << to_lower("HELLO!") << " " << boost::to_lower_copy("HELLO!"s) << endl;
cout << to_title("hELLO!") << endl;
cout << fold_case("HELLO!") << endl;
return 0;
}
HELLO! HELLO!
hello! hello!
Hello!
hello!
HELLO! HELLO!
hello! hello!
hELLO!
hello!
/std:c++latest
It seems that the Boost that is installed by vcpkg doesn't get compiled
with ICU, which is apparently required for boost::locale::to_title
to
function correctly.
vcpkg (https://github.com/Microsoft/vcpkg) by default installs Boost without depending on ICU for the Boost::locale and Boost::regex libraries.
So, instead of installing those like this:
vcpkg install boost-locale:x64-windows boost-regex:x64-windows
I had to do the following:
vcpkg install boost-locale[icu]:x64-windows boost-regex[icu]:x64-windows
This automatically fetches and builds the ICU library, and (since I had already installed Boost without ICU) it automatically rebuilt all of the Boost libraries.
I wish the Boost documentation for those libraries made it clear that you needed ICU to use the functionality that requires it.