I'm using libcurl
to upload some files to my server. I need to handle files whose names are in different languages e.g. Chinese, Hindi, etc. For that, I need to handle files using std::wstring
instead of std::string
.
libcurl
has a function with a prototype like below:
CURLcode curl_mime_filename(curl_mimepart *part, const char *filename);
But I cannot pass std::wstring::c_str()
because it will return const wchar_t*
instead of const char*
.
Edit: I still don't know what encoding scheme is used by the server as it is a third party app so I used std::wstring
for handling filenames and the conversion from std::wstring
to std::string
is done by the below function I found on this forum.
std::string ws2s(const std::wstring& wstr)
{
using convert_typeX = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_typeX, wchar_t> converterX;
return converterX.to_bytes(wstr);
}