使用自定义numpunct格式化数字会导致MSVCP140D.dll中的运行时失败

时间:2016-04-28 12:16:25

标签: c++ locale

我正在尝试创建一个函数,用于创建一个整数格式化数字的字符串。我正在尝试使用自定义numpunct的语言环境,我可以自定义。 我不能使用现有的语言环境,因为我的项目是多平台的,在某些平台上它可能没有语言环境支持,所以我自己创建了一个。 这是我添加到项目中的代码:

class comma_numpunct : public std::numpunct<char>
{
  virtual char do_thousands_sep() const
  {
    return '*';
  }

  virtual std::string do_grouping() const
  {
    return "\02";
  }
};

std::string createString(const int x) {
  std::locale comma_locale(std::locale(), new comma_numpunct);
  std::stringstream ss;
  ss.imbue(comma_locale);
  ss << x;
  return ss.str();
}

代码编译正常但是当我在Visual Studio 2015中以调试模式执行它时,我收到运行时错误,ss << x;中的MSVCP140D.dll中的断言失败

以下是完整的错误消息:

---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!

Program: C:\WINDOWS\SYSTEM32\MSVCP140D.dll
File: f:\dd\vctools\crt\crtw32\stdhpp\xmemory0
Line: 106

Expression: "(_Ptr_user & (_BIG_ALLOCATION_ALIGNMENT - 1)) == 0" && 0

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

---------------------------
Interrompi   Riprova   Ignora   
---------------------------

我错过了什么?

0 个答案:

没有答案