wstring

Does C++0x support std::wstring conversion to/from UTF-8 byte sequence?

跟風遠走 提交于 2019-12-03 12:50:34
I saw that C++0x will add support for UTF-8, UTF-16 and UTF-32 literals. But what about conversions between the three representations ? I plan to use std::wstring everywhere in my code. But I also need to manipulate UTF-8 encoded data when dealing with files and network. Will C++0x provide also support for these operations ? In C++0x, char16_t and char32_t will be used to store UTF-16 and UTF-32 and not wchar_t . From the draft n2798: 22.2.1.4 Class template codecvt 2 The class codecvt is for use when converting from one codeset to another, such as from wide characters to multibyte characters

Is there any built-in function that convert wstring or wchar_t* to UTF-8 in Linux?

孤人 提交于 2019-12-01 16:03:52
问题 I want to convert wstring to UTF-8 Encoding, but I want to use built-in functions of Linux. Is there any built-in function that convert wstring or wchar_t* to UTF-8 in Linux with simple invokation ? Example: wstring str = L"file_name.txt"; wstring mode = "a"; fopen([FUNCTION](str), [FUNCTION](mode)); // Simple invoke. cout << [FUNCTION](str); // Simple invoke. 回答1: The C++ language standard has no notion of explicit encodings. It only contains an opaque notion of a "system encoding", for

String class allocating on stack for small strings?

主宰稳场 提交于 2019-12-01 16:01:52
Do anyone know if there is a STL interface compatible string class that allocates memory for small strings on the stack (up to a certain threshold) and the heap for larger strings ? I'm looking to optimize a program and I'm using allot of small local strings that easily could fit on the stack, instead of being allocated on the heap. Björn Pollex You can provide a custom allocator for std::basic_string (it is the third template argument). This answer explains how use that and links to an implementation of a stack-allocator that can be used. The vstring (__versa_string) implementation from gcc

C++ lpcwstr to wstring

爱⌒轻易说出口 提交于 2019-12-01 10:52:46
问题 I would like to convert a LPCWSTR to wstring in C++ (VS 2010). I want to use this in OutputDebugStringW(). Thank you. 回答1: Well just pass the LPCWSTR to the constructor of wstring like this: LPCWSTR str=L"fun"; wstring str2(str); 来源: https://stackoverflow.com/questions/15743838/c-lpcwstr-to-wstring

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

孤者浪人 提交于 2019-12-01 06:04:34
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 classes This would give me better platform independency, but it is ridiculous to reimplement the wheel. I

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

时间秒杀一切 提交于 2019-11-30 03:23:47
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 or XSL:FO for reporting purposes. My feeling based on what I have read is that the HTML should be

How to convert std::wstring to numeric type(int, long, float)?

耗尽温柔 提交于 2019-11-29 15:01:38
问题 What's the best way to convert std::wstring to numeric type, such as int, long, float or double? 回答1: Either use boost::lexical_cast<>: #include <boost/lexical_cast.hpp> std::wstring s1(L"123"); int num = boost::lexical_cast<int>(s1); std::wstring s2(L"123.5"); double d = boost::lexical_cast<double>(s2); These will throw a boost::bad_lexical_cast exception if the string can't be converted. The other option is to use Boost Qi (a sublibrary of Boost.Spirit): #include <boost/spirit/include/qi

Unable to write a std::wstring into wofstream

浪子不回头ぞ 提交于 2019-11-29 11:39:40
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 Smith entered in the line edit is John Smith10 . but for unicode strings, nothing. First I thought that is

Convert a String^ to wstring C++

僤鯓⒐⒋嵵緔 提交于 2019-11-29 08:07:30
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! 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: #include <msclr\marshal.h> #include <msclr\marshal_cppstd.h> What this marshal_as specialization looks like

Handling UTF-8 in C++

▼魔方 西西 提交于 2019-11-29 03:52:48
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 crash, but a normal exit, yet I find that hard to believe. robert petranovic Don't use wstring on Linux.