【问题标题】:wstring string converter in BoostBoost中的wstring字符串转换器
【发布时间】:2012-03-29 08:03:21
【问题描述】:

我使用 Boost 库来实现我的应用程序。我的应用程序的数据模型中的所有字符串字符都是宽字符(wchar_t 类型)。但是在 boost 库中,有些类只处理窄字符(char 类型),即“address boost::asio::ip::address::from_string(const char* str)”。所以我需要在调用 boost 函数时在 std::string 和 std::wstring 之间进行转换。

  1. 字符串转换是否存在性能问题?
  2. Boost 中的转换器,它使 std::wstring 和 std::string 之间的转换具有良好的性能?

更新

关于转换器功能。我发现下面的代码有效。

std::wstring wstr(L"Hello World");
const std::string nstr( wstr.begin(),  wstr.end());
const std::wstring wstr2(nstr.begin(), nstr.end());

【问题讨论】:

  • 希望您的宽字符串中没有任何非 ascii 字符...

标签: string boost converter


【解决方案1】:

自己添加研究结论。

关于字符串转换的性能开销。我调试了上面的功能。转换由 C-cast char by char 实现。时间复杂度是O(L),L是字符串的长度。在我的应用程序中,需要转换的字符串不是很长。因此,我认为转换不会导致任何明显的性能延迟。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 2014-10-18
    • 1970-01-01
    • 2011-05-20
    相关资源
    最近更新 更多