wstring

endl doesn't work with wstring (unicode)

ⅰ亾dé卋堺 提交于 2019-12-07 08:56:46
问题 Here is the code: std::ofstream f("file1.txt"); f<<"123"<<std::endl<<"456"; //(*1) /*std::stringstream ordinary_strstream; This works too ordinary_strstream<<"123"<<'\n'<<"456"; f<<ordinary_strstream.str();*/ std::wstringstream s; s<<L"123"<<std::endl<<L"456"; //(*2) s<<L"123"<<L"\n"<<L"456"; //(*3) s<<"123"<<WCHAR(13)<<WCHAR(10)<<"456";//(*4) HANDLE h =CreateFileW(L"file2.txt", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); ULONG l;

Portable wchar_t in C++

六月ゝ 毕业季﹏ 提交于 2019-12-07 05:37:08
问题 Is there a portable wchar_t in C++? On Windows, its 2 bytes. On everything else is 4 bytes. I would like to use wstring in my application, but this will cause problems if I decide down the line to port it. 回答1: If you're dealing with use internal to the program, don't worry about it; a wchar_t in class A is the same as in class B. If you're planning to transfer data between Windows and Linux/MacOSX versions, you've got more than wchar_t to worry about, and you need to come up with means to

How do I convert a string to a wstring using the value of the string?

不想你离开。 提交于 2019-12-06 13:52:01
问题 I'm new to C++ and I have this issue. I have a string called DATA_DIR that I need for format into a wstring. string str = DATA_DIR; std::wstring temp(L"%s",str); Visual Studio tells me that there is no instance of constructor that matches with the argument list. Clearly, I'm doing something wrong. I found this example online std::wstring someText( L"hello world!" ); which apparently works (no compile errors). My question is, how do I get the string value stored in DATA_DIR into the wstring

getting a sub string of a std::wstring

守給你的承諾、 提交于 2019-12-06 09:43:48
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; } This should work: live on Coliru #include <iostream> #include <string> #include <boost/regex/pending/unicode_iterator.hpp> using namespace std; template <typename C> std::string to_utf8

why std::wofstream do not print all wstring into file?

送分小仙女□ 提交于 2019-12-06 00:16:30
I have a std::wstring whose size is 139,580,199 characters. For debugging I printed it into file with this code: std::wofstream f(L"C:\\some file.txt"); f << buffer; f.close(); After that noticed that the end of string is missing. The created file size is 109,592,584 bytes (and the "size on disk" is 109,596,672 bytes). Also checked if buffer contains null chars, did this: size_t pos = buffer.find(L'\0'); Expecting result to be std::wstring::npos but it is 18446744073709551615 , but my string doesn't have null char at the end so probably it's ok. Can somebody explain, why I have not all string

c++ can't convert string to wstring

痞子三分冷 提交于 2019-12-05 19:33:35
I would like to convert a string variable to wstring due to some german characters that cause problem when doing a substr over the variable. The start position is falsified when any these special characters is present before it. (For instance: for "ä" size() returns 2 instead of 1) I know that the following conversion works: wstring ws = L"ä"; Since, I am trying to convert a variable, I would like to know if there is an alternative way for it such as wstring wstr = L"%s"+str //this is syntaxically wrong, but wanted sth alike Beside that, I have already tried the following example to convert

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

痴心易碎 提交于 2019-12-04 21:20:20
问题 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 ? 回答1: 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

How do I convert a string to a wstring using the value of the string?

南楼画角 提交于 2019-12-04 19:24:42
I'm new to C++ and I have this issue. I have a string called DATA_DIR that I need for format into a wstring. string str = DATA_DIR; std::wstring temp(L"%s",str); Visual Studio tells me that there is no instance of constructor that matches with the argument list. Clearly, I'm doing something wrong. I found this example online std::wstring someText( L"hello world!" ); which apparently works (no compile errors). My question is, how do I get the string value stored in DATA_DIR into the wstring constructor as opposed to something arbitrary like "hello world"? Here is an implementation using

UTF-8 Compatibility in C++

左心房为你撑大大i 提交于 2019-12-04 01:16:45
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 error when I use wchar_t , wstring and wstringstream .) Additionally, I know that UTF is variable length.

how can I convert wstring to u16string?

大城市里の小女人 提交于 2019-12-03 16:19:42
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(), -1, szDest, iSize,0,0);'s szDest . Cause of u16string can't use with LPSTR . How can I fix this code