标签: wstring

9
推荐指数
2
解决办法
7495
查看次数

字符串类在堆栈上为小字符串分配?

有没有人知道是否有一个STL接口兼容的字符串类,它为堆栈上的小字符串分配内存(达到某个阈值),堆是否为更大的字符串?

我正在寻找优化程序,我正在使用很多可以轻松放在堆栈上的小型本地字符串,而不是在堆上分配.

c++ string memory-management stl wstring

9
推荐指数
1
解决办法
2039
查看次数

使用wstring获取行读取文件

我有一个包含文本的文件,我想从这个文件中的每一行变成一个std::wstring变量.如果我这样做我得到一个错误,那么是否可以使用std::wstring或者我必须使用std::string?这是我的代码:

std::ifstream fichier( "text.txt" );

if ( fichier )
{
  std::wstring ligne;

  while ( std::getline( fichier, ligne ) )
  {
      //work with ligne
  }
}
Run Code Online (Sandbox Code Playgroud)

如前所述,如果我取代std::wstringstd::string我有没有错误.

c++ string ifstream wstring

9
推荐指数
1
解决办法
1万
查看次数

C++ 0x是否支持将std :: wstring转换为UTF-8字节序列?

我看到C++ 0x将添加对UTF-8,UTF-16和UTF-32文字的支持.但是这三种表述之间的转换呢?

我打算在我的代码中到处使用std :: wstring.但在处理文件和网络时,我还需要操纵UTF-8编码数据.C++ 0x是否也支持这些操作?

c++ unicode utf-8 wstring c++11

8
推荐指数
1
解决办法
3147
查看次数

Android NDK C++'wstring'支持

我有用C++编写的源代码/ lib - 现在我想在Android NDK项目(NDK 6)中编译和使用相同的代码.我能够编译大多数C++文件,除了基于"std :: wstring"的功能.

在Application.mk中,当我指定APP_STL: = stlport_static它然后它编译std::wstring基于代码,但当我指定APP_STL: = gnustl_static它无法编译.我不知道如何解决std::wstring相关问题APP_STL: = gnustl_static

任何指针或帮助将非常感激.

c++ android wstring android-ndk

8
推荐指数
1
解决办法
3323
查看次数

使用wcstombs_s将std :: wsting转换为char*

我输入的字符串只包含数字(只是简单的拉丁文字符串,0-9,所以例如"0123"),存储为std :: wstring,我需要每个字符串作为char*.这对我来说最好的方法是什么?这是我最初的做法:

void type::convertWStringToCharPtr(_In_ std::wstring input, _Out_ char * outputString)
{
    outputString = new char[outputSize];
    size_t charsConverted = 0;
    const wchar_t * inputW = input.c_str();
    wcstombs_s(&charsConverted, outputString, sizeof(outputString), inputW, input.length());
}
Run Code Online (Sandbox Code Playgroud)

编辑:下面的代码工作.谢谢大家!

void type::convertWStringToCharPtr(_In_ std::wstring input, _Out_ char * outputString)
{
    size_t outputSize = input.length() + 1; // +1 for null terminator
    outputString = new char[outputSize];
    size_t charsConverted = 0;
    const wchar_t * inputW = input.c_str();
    wcstombs_s(&charsConverted, outputString, outputSize, inputW, input.length());
}
Run Code Online (Sandbox Code Playgroud)

c++ string wstring c++11

7
推荐指数
2
解决办法
1万
查看次数

在libarchive中设置UTF-8路径名头

摘要

如何在C++中使用libarchive编写zip文件,以便路径名是UTF-8编码的?使用UTF-8路径名时,使用OS X/Linux/Windows 8/7-Zip/WinZip时,将正确解码特殊字符.

细节

我正在尝试使用libarchive编写zip存档,在Windows上使用Visual C++ 2013进行编译.

我希望能够将带有非ASCII字符的文件(例如äöü.txt)添加到zip存档中.

在libarchive中有四个函数来设置pathname标头:

void archive_entry_set_pathname(struct archive_entry *, const char *);
void archive_entry_copy_pathname(struct archive_entry *, const char *);
void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
int  archive_entry_update_pathname_utf8(struct archive_entry *, const char *);
Run Code Online (Sandbox Code Playgroud)

不幸的是,它们似乎都没有用.

特别是,我试过:

const char* myUtf8Str = ...
archive_entry_update_pathname_utf8(entry, myUtf8Str);
// this sounded like the most straightforward solution
Run Code Online (Sandbox Code Playgroud)

const wchar_t* myUtf16Str = ...
archive_entry_copy_pathname_w(entry, myUtf16Str);
// UTF-16 encoded strings seem to be the default on Windows
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,生成的zip存档都不会在Windows资源管理器和7-Zip中正确显示文件名.

我确信我的输入字符串编码正确,因为我从Qt QString实例转换它们在我的代码的其他部分非常有效:

const char* …
Run Code Online (Sandbox Code Playgroud)

c++ zip utf-8 wstring libarchive

7
推荐指数
1
解决办法
1106
查看次数

将std :: wstring拆分为std :: vector

此问题显示如何使用单个字符分隔符将a拆分string为a .vector

问题:将std :: string拆分为向量的正确方法

然而,应用这种技术wstring并不像我想象的那么容易.因此,这绝对不是重复!

wstringstream stringStream(str);
istream_iterator<wstring> begin(stringStream);
istream_iterator<wstring> end;
List = vector<wstring>(begin, end);
copy(List.begin(), List.end(), ostream_iterator<wstring>(cout, ";"));
Run Code Online (Sandbox Code Playgroud)

第二行无法使用VS2015进行编译.并使用istream_iterator<wstring, wchar_t>导致编译错误iterator.h.

我怎样才能分割std::wstringstd::vector由分离";"

c++ string vector wstring

7
推荐指数
1
解决办法
6072
查看次数

如何将 wstring 转换为 wchar_t*?C++

我想将 wstring 转换为 wchar_t*。我已经尝试了我所知道的一切,请帮忙。我想将 wstring 转换为 wchar_t*。

c++ wchar-t wstring

7
推荐指数
1
解决办法
2万
查看次数

在 C++17/C++20 中从 wstring 到 u16string 并返回(符合标准)的转换

我的主要平台是 Windows,这就是我在内部使用 UTF-16(主要是 BMP 字符串)的原因。我想对这些字符串使用控制台输出。

不幸的是没有std::u16coutstd::u8cout,所以我需要使用std::wcout。因此,我必须将 u16strings 转换为 wstrings - 最好(也是最简单)的方法是什么?

在 Windows 上,我知道 wstring 指向 UTF16 数据,因此我可以创建一个简单的 std::u16string_view 使用相同的数据(无转换)。但是在 Linux 上 wstring 通常是 UTF32 ......有没有办法在没有宏和假设 sizeof(wchar_t) == 2 => utf16 的情况下做到这一点?

c++ utf-16 wstring utf-32 c++17

7
推荐指数
1
解决办法
273
查看次数