wstring

C++ substring multi byte characters

[亡魂溺海] 提交于 2020-01-24 06:28:48
问题 I am having this std::string which contains some characters that span multiple bytes. When I do a substring on this string, the output is not valid, because ofcourse, these characters are counted as 2 characters. In my opinion I should be using a wstring instead, because it will store these characters in as one element instead of more. So I decided to copy the string into a wstring, but ofcourse this does not make sense, because the characters remain split over 2 characters. This only makes

OpenCV imread with foreign characters

依然范特西╮ 提交于 2020-01-04 10:38:07
问题 We're working on a project using OpenCV 2.4.6 and Qt 5.1.1 in C++. We have to load images for image processing at several points in our code, which we did using cv::imread , as normal. However, we wanted to make software compatible with other language filesystems, and found that having file paths with foreign characters would fail to load. The problem, we believe, has to do with the fact that imread can only take in a std::string (or char* ), and casting a path with non Latin-1 symbols to a

Conversion from string to wstring is causing ú to lose encoding

情到浓时终转凉″ 提交于 2020-01-02 10:18:30
问题 The variable filepath which is a string contains the value Música . I have the following code: wstring fp(filepath.length(), L' '); copy(filepath.begin(), filepath.end(), fp.begin()); fp then contains the value M?sica . How do I convert filepath to fp without losing the encoding for the ú character? 回答1: Use the function MultiByteToWideChar. Sample code: std::string toStdString(const std::wstring& s, UINT32 codePage) { unsigned int bufferSize = (unsigned int)s.length()+1; char* pBuffer = new

how can I convert wstring to u16string?

≡放荡痞女 提交于 2020-01-01 06:04:07
问题 I want to convert wstring to u16string in C++. I can convert wstring to string, or reverse. But I don't know how convert to u16string . u16string CTextConverter::convertWstring2U16(wstring str) { int iSize; u16string szDest[256] = {}; memset(szDest, 0, 256); iSize = WideCharToMultiByte(CP_UTF8, NULL, str.c_str(), -1, NULL, 0,0,0); WideCharToMultiByte(CP_UTF8, NULL, str.c_str(), -1, szDest, iSize,0,0); u16string s16 = szDest; return s16; } Error in WideCharToMultiByte(CP_UTF8, NULL, str.c_str(

Solution for missing std::wstring support in Android NDK?

人走茶凉 提交于 2019-12-30 09:30:17
问题 I have a game which uses std::wstring as its basic string type in thousand of places as well as doing operations with wchar_t and its functions: wcsicmp() wcslen() vsprintf(), etc. The problem is wstring is not supported in R5c (latest ndk at the time of this writting). I can't change the code to use std::string because of internationalization and I would be breaking the game engine which is used by many games ... Which options do I have? 1 - Replace string and wstring with my own string

fgetws fails to get the exact wide char string from FILE*

て烟熏妆下的殇ゞ 提交于 2019-12-25 03:01:12
问题 I am using fgetws to get some string line by line from a FILE. The FILE I have is from a popen command. Here is the code snippet: FILE* pInstalledApps = popen( command.c_str(), "r" ); if( NULL != pInstalledApps ) { wchar_t currentAppPath [kMaximumAppPathLength]; // Reading app paths one line at a time. while ( ! feof (pInstalledApps) ) { if ( fgetws ( currentAppPath, kMaximumAppPathLength, pInstalledApps) == NULL ) { break; } wchar_t *pCharPos = NULL; if ( ( pCharPos = wcschr( currentAppPath,

Converting std::wstring to SQLWCHAR *

时光总嘲笑我的痴心妄想 提交于 2019-12-24 00:34:08
问题 I have a C++ program that is dynamically creating a query string which will then be passed to a SQLExecDirect call to connect to a database using ODBC. I'm having trouble passing the variable from one function to another, so I think I must be missing something basic? In the ConstructQuery function (which returns type SQLWCHAR * ), I have: std::wstring test = L"test string"; //This test string will actually be several concatenated strings SQLWCHAR *statement = (SQLWCHAR *)test.c_str(); std:

getting a sub string of a std::wstring

我的梦境 提交于 2019-12-22 13:47:42
问题 How can I get a substring of a std::wstring which includes some non-ASCII characters? The following code does not output anything: (The text is an Arabic word contains 4 characters where each character has two bytes, plus the word "Hello") #include <iostream> #include <string> using namespace std; int main() { wstring s = L"سلام hello"; wcout << s.substr(0,3) << endl; wcout << s.substr(4,5) << endl; return 0; } 回答1: This should work: live on Coliru #include <iostream> #include <string>

UTF-8 Compatibility in C++

江枫思渺然 提交于 2019-12-21 07:37:25
问题 I am writing a program that needs to be able to work with text in all languages. My understanding is that UTF-8 will do the job, but I am experiencing a few problems with it. Am I right to say that UTF-8 can be stored in a simple char in C++? If so, why do I get the following warning when I use a program with char , string and stringstream : warning C4566: character represented by universal-character-name '\uFFFD' cannot be represented in the current code page (1252) . (I do not get that

Android NDK C++ 'wstring' support

人走茶凉 提交于 2019-12-21 04:27:11
问题 I have source code/lib written in C++ - now i would like to compile and use the same in Android NDK project (NDK 6). I am able to compile most of the C++ files except "std::wstring" based functionality. In Application.mk when i specify APP_STL: = stlport_static then it compiles std::wstring based code but when i specify APP_STL: = gnustl_static it fails to compile. I do not know how to resolve std::wstring related issue with APP_STL: = gnustl_static Any pointer or help on this would be