I am trying to use this code snippet from this Stack Overflow answer: A: How to convert an instance of std::string to lower case
#include <unicode/unistr.h>
#include <unicode/ustream.h>
#include <unicode/locid.h>
#include <iostream>
int main()
{
/* "Odysseus" */
char const * someString = u8"ΟΔΥΣΣΕΥΣ";
icu::UnicodeString someUString( someString, "UTF-8" );
// Setting the locale explicitly here for completeness.
// Usually you would use the user-specified system locale,
// which *does* make a difference (see ı vs. i above).
std::cout << someUString.toLower( "el_GR" ) << "n";
std::cout << someUString.toUpper( "el_GR" ) << "n";
return 0;
}
This is not working for me. I am on a windows machine and I downloaded the windows 2019 ICU zip from this link: https://github.com/unicode-org/icu/releases/tag/release-72-1
and after downloading it, I linked it into my project. I made sure my system environment variables point to the bin64 folder of that library, and I linked the additional includes to the include folder, and I added the lib64 folder via my linker and I also went into linker -> input in the VS code settings and included 3 files there
icuuc.lib
icuin.lib
icuio.lib
The code is providing this output:
Original string: ΟΔΥΣΣΕΥΣ
Lowercase:
Uppercase: ΟΔΥΣΣΕΥΣ
when I do this
#include "io.h"
#include "windows.h"
void
io::testfn()
{
SetConsoleOutputCP(CP_UTF8); //without this the letters are all "->->->..."
/* "Odysseus" */
char const* someString = u8"ΟΔΥΣΣΕΥΣ";
icu::UnicodeString someUString(someString, "UTF-8");
std::cout << "Original string: " << someUString << std::endl;
icu::UnicodeString lowerString = someUString.toLower("el_GR");
icu::UnicodeString upperString = someUString.toUpper("el_GR");
// Debugging: print the results
std::cout << "Lowercase: " << lowerString << std::endl;
std::cout << "Uppercase: " << upperString << std::endl;
}
I have tried saving the file using save as -> ‘save with encoding’ and UTF8 without signature is providing the above output and anything else I try is worse. Why can’t I do this? Also is there no easier way to make a string “tolower” in c++? I was making my own tolower function but my bf who is a c++ dev told me I should use the boost library but then on the linked stackoverflow it says not to use boost because it will cause unseen errors.
I have tried reading about this and using ai and asking other programmers I know.
Also if I do this:
icu::UnicodeString englishString = someUString.toUpper("en_US");
std::cout << "English: " << englishString << std::endl;
then I get this output
Original string: ΟΔΥΣΣΕΥΣ
Lowercase:
Uppercase: ΟΔΥΣΣΕΥΣ
English: ΟΔΥΣΣΕΥΣ
user284985 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.