wstring

Confused about C++'s std::wstring, UTF-16, UTF-8 and displaying strings in a windows GUI

流过昼夜 提交于 2019-11-29 00:26:58
问题 I'm working on a english only C++ program for Windows where we were told "always use std::wstring", but it seems like nobody on the team really has much of an understanding beyond that. I already read the question titled "std::wstring VS std::string. It was very helpful, but I still don't quite understand how to apply all of that information to my problem. The program I'm working on displays data in a Windows GUI. That data is persisted as XML. We often transform that XML using XSLT into HTML

How to initialize and print a std::wstring?

匆匆过客 提交于 2019-11-28 20:02:31
I had the code: std::string st = "SomeText"; ... std::cout << st; and that worked fine. But now my team wants to move to wstring . So I tried: std::wstring st = "SomeText"; ... std::cout << st; but this gave me a compilation error: Error 1 error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'const char [8]' to 'const std::basic_string<_Elem,_Traits,_Ax> &' D:...\TestModule1.cpp 28 1 TestModule1 After searching the web I read that I should define it as: std::wstring st = L"SomeText"; // Notice the "L"

Unable to write a std::wstring into wofstream

谁都会走 提交于 2019-11-28 04:51:59
问题 I'm using Qt/C++ on a Linux system. I need to convert a QLineEdit 's text to std::wstring and write it into a std::wofstream . It works correctly for ascii strings, but when I enter any other character (Arabic or Uzbek) there is nothing written in the file. (size of file is 0 bytes). this is my code: wofstream customersFile; customersFile.open("./customers.txt"); std::wstring ws = lne_address_customer->text().toStdWString(); customersFile << ws << ws.length() << std::endl; Output for John

Convert a String^ to wstring C++

别说谁变了你拦得住时间么 提交于 2019-11-28 02:00:55
问题 I programmed a little Application in C++. There is a ListBox in the UI. And I want to use the selected Item of ListBox for an Algorithm where I can use only wstrings. All in all I have two questions: -how can I convert my String^ curItem = listBox2->SelectedItem->ToString(); to a wstring test? -What means the ^ in the code? Thanks a lot! 回答1: It should be as simple as: std::wstring result = msclr::interop::marshal_as<std::wstring>(curItem); You'll also need header files to make that work:

How to convert string to wstring in C++

心已入冬 提交于 2019-11-28 00:31:31
I have programmed some code but there is some problem. In this codes i am trying to convert string to wstring. But this string have "█" characters. This character have 219 ascii code. This conversion getting error. In my code: string strs= "█and█something else"; wstring wstr(strs.begin(),strs.end()); After debugging, I am getting result like this ?and?something else How do I correct this problem? Thanks... Kerrek SB The C-library solution for converting between the system's narrow and wide encoding use the mbsrtowcs and wcsrtombs functions from the <cwchar> header. I've spelt this out in this

Handling UTF-8 in C++

六眼飞鱼酱① 提交于 2019-11-27 17:49:35
问题 To find out if C++ is the right language for a project of mine, I wanna test the UTF-8 capabilities. According to references, I built this example: #include <string> #include <iostream> using namespace std; int main() { wstring str; while(getline(wcin, str)) { wcout << str << endl; if(str.empty()) break; } return 0; } But when I type in an UTF-8 character, it misbehaves: $ > ./utf8 Hello Hello für f $ > Not only it doesn't print the ü , but also quits immediately. gdb told me there was no

Convert wstring to string encoded in UTF-8

 ̄綄美尐妖づ 提交于 2019-11-27 07:07:49
I need to convert between wstring and string. I figured out, that using codecvt facet should do the trick, but it doesn't seem to work for utf-8 locale. My idea is, that when I read utf-8 encoded file to chars, one utf-8 character is read into two normal characters (which is how utf-8 works). I'd like to create this utf-8 string from wstring representation for library I use in my code. Does anybody know how to do it? I already tried this: locale mylocale("cs_CZ.utf-8"); mbstate_t mystate; wstring mywstring = L"čřžýáí"; const codecvt<wchar_t,char,mbstate_t>& myfacet = use_facet<codecvt<wchar_t

Read Unicode UTF-8 file into wstring

烂漫一生 提交于 2019-11-27 06:58:21
How can I read a Unicode (UTF-8) file into wstring (s) on the Windows platform? With C++11 support, you can use std::codecvt_utf8 facet which encapsulates conversion between a UTF-8 encoded byte string and UCS2 or UCS4 character string and which can be used to read and write UTF-8 files, both text and binary. In order to use facet you usually create locale object that encapsulates culture-specific information as a set of facets that collectively define a specific localized environment. Once you have a locale object, you can imbue your stream buffer with it: #include <sstream> #include <fstream

Case insensitive std::string.find()

你说的曾经没有我的故事 提交于 2019-11-27 00:36:33
I am using std::string 's find() method to test if a string is a substring of another. Now I need case insensitive version of the same thing. For string comparison I can always turn to stricmp() but there doesn't seem to be a stristr() . I have found various answers and most suggest using Boost which is not an option in my case. Additionally, I need to support std::wstring / wchar_t . Any ideas? Kirill V. Lyadvinsky You could use std::search with a custom predicate. #include <locale> #include <iostream> #include <algorithm> using namespace std; // templated version of my_equal so it could work

How to convert string to wstring in C++

旧城冷巷雨未停 提交于 2019-11-26 23:27:04
问题 I have programmed some code but there is some problem. In this codes i am trying to convert string to wstring. But this string have "█" characters. This character have 219 ascii code. This conversion getting error. In my code: string strs= "█and█something else"; wstring wstr(strs.begin(),strs.end()); After debugging, I am getting result like this ?and?something else How do I correct this problem? Thanks... 回答1: The C-library solution for converting between the system's narrow and wide