Questions tagged [wstring]

C++ standard library class to hold strings with wide characters. Behaves differently on Windows vs. Linux.

C++ standard library class to hold strings with wide characters. On Linux, it holds 4-byte characters; while on Windows, it holds 2-byte characters.

378 questions
892
votes
13 answers

std::wstring VS std::string

I am not able to understand the differences between std::string and std::wstring. I know wstring supports wide characters such as Unicode characters. I have got the following questions: When should I use std::wstring over std::string? Can…
Appu
269
votes
19 answers

How to convert wstring into string?

The question is how to convert wstring to string? I have next example : #include #include int main() { std::wstring ws = L"Hello"; std::string s( ws.begin(), ws.end() ); //std::cout <<"std::string = …
BЈовић
  • 62,405
  • 41
  • 173
  • 273
224
votes
20 answers

C++ Convert string (or char*) to wstring (or wchar_t*)

string s = "おはよう"; wstring ws = FUNCTION(s, ws); How would i assign the contents of s to ws? Searched google and used some techniques but they can't assign the exact content. The content is distorted.
Samir
  • 3,923
  • 9
  • 36
  • 43
89
votes
11 answers

Case insensitive std::string.find()

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…
wpfwannabe
  • 14,587
  • 16
  • 78
  • 129
87
votes
2 answers

What's "wrong" with C++ wchar_t and wstrings? What are some alternatives to wide characters?

I have seen a lot of people in the C++ community(particularly ##c++ on freenode) resent the use of wstrings and wchar_t, and their use in the windows api. What is exactly "wrong" with wchar_t and wstring, and if I want to support…
Ken Li
  • 2,578
  • 4
  • 25
  • 26
82
votes
6 answers

How to initialize and print a std::wstring?

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…
Roee Gavirel
  • 18,955
  • 12
  • 67
  • 94
48
votes
7 answers

Read Unicode UTF-8 file into wstring

How can I read a Unicode (UTF-8) file into wstring(s) on the Windows platform?
Abdelwahed
  • 1,694
  • 4
  • 21
  • 31
26
votes
8 answers

Convert wstring to string encoded in UTF-8

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…
Trakhan
  • 463
  • 1
  • 6
  • 15
24
votes
9 answers

How to portably write std::wstring to file?

I have a wstring declared as such: // random wstring std::wstring str = L"abcàdëefŸg€hhhhhhhµa"; The literal would be UTF-8 encoded, because my source file is. [EDIT: According to Mark Ransom this is not necessarily the case, the compiler will…
user1481860
22
votes
4 answers

How to convert std::wstring to LPCTSTR in C++?

I have Windows registry key value in wstring format. Now I want to pass it to this code (first argument - path to javaw.exe): std::wstring somePath(L"....\\bin\\javaw.exe"); if (!CreateProcess("C:\\Program Files\\Java\\jre7\\bin\\javaw.exe",…
Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117
21
votes
4 answers

How can I get the byte size of std::wstring?

I am using std::wstring as my Unicode style string. Now I want to get the byte size of a wstring. If I use size() method of wstring, I just get the total number of chars in my wstring. But the byte should be size() * 2. Is there an official way…
Hooch
  • 28,817
  • 29
  • 102
  • 161
21
votes
3 answers

Best way to convert std::wstring to QString

I'm currently working on a larger project, where the "logic" is implemented in standard C++ with all strings being handled with std::wstring and the UI part is implemented using Qt and thus necessarily QString (Bonus question: is this true?). What…
mort
  • 12,988
  • 14
  • 52
  • 97
20
votes
5 answers

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

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…
Dave
  • 885
  • 2
  • 10
  • 20
20
votes
6 answers

What is the optimal multiplatform way of dealing with Unicode strings under C++?

I know that there are already several questions on StackOverflow about std::string versus std::wstring or similar but none of them proposed a full solution. In order to obtain a good answer I should define the requirements: multiplatform usage,…
sorin
  • 161,544
  • 178
  • 535
  • 806
18
votes
1 answer

Check if std::wstring is null or empty

How to check if an std::wstring is null or empty?
subs
  • 2,189
  • 12
  • 35
  • 59
1
2 3
25 26