wstring

C++: using std::wstring in API function

I'm using the SHGetSpecialFolderLocation API function. My application is set to "Use Unicode Character Set". Here's what I have so far: int main ( int, char ** ) { LPITEMIDLIST pidl; HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl); /* Confused at this point */ wstring wstrPath; wstrPath.resiz...

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 various answers and most suggest using Boost which is not an option in my case. Addition...

Why doesn't wstring::c_str cause a memory leak if not properly deleted

Code Segment 1: wchar_t *aString() { wchar_t *str = new wchar[5]; wcscpy(str, "asdf\0"); return str; } wchar_t *value1 = aString(); Code Segment 2 wstring wstr = L"a value"; wchar_t *value = wstr.c_str(); If value from code segment 2 is not deleted then an memory leak does not occur. However, if value1 from code seg...

How to create a std::wstring using the ascii codes of characters in C++?

I need to create a wstring with the chars that have the following ascii values: 30, 29, 28, 27, 26, 25. In VB6, I would do asc(30) + asc(29)+ etc... What's the C++ equivalent? Thanks! ...

Arguments for and against supporting std::wstring exclusively in cross-platform library

I'm currently developing a cross-platform C++ library which I intend to be Unicode aware. I currently have compile-time support for either std::string or std::wstring via typedefs and macros. The disadvantage with this approach is that it forces you to use macros like L("string") and to make heavy use of templates based on character type...

Can't instantiate an istring_iterator using a wistringstream

I'm trying to split a string using the method found in this thread, but I'm trying to adapt it to a wstring. However, I have stumbled upon a weird error. Check the code: #include <iostream> #include <sstream> #include <string> #include <vector> #include <algorithm> #include <iterator> using namespace std; int main(void) { wstring ...

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 decide what encoding to use - let us instead assume that I read this string from a file enc...