调试断言在使用 ispunct('ø') 时失败
Debug Assertion Failed when using ispunct('ø')
我正在编写一个处理大部分文本的程序,需要删除标点符号。我遇到了调试断言失败错误,并将其隔离为此:它在非英语字母上测试 ispunct(( 时发生。
我的测试程序现在是这样的:
主.c
int main() {
ispunct('ø');
cin.get();
return 0;
}
"调试断言失败"窗口如下所示:错误的屏幕截图
我尝试过的所有非英语字母都会导致此问题,包括"æ","ø","å","é"等。这可能是我忽略的非常简单的事情,所以我感谢任何帮助!
字符'ø'
必须表示为unsigned char
,否则应使用类型wchar_t
和std::ispunct
,例如:
#include <iostream>
#include <locale>
int main()
{
const wchar_t c = L'ø';
std::locale loc("en_US.UTF-8");
std::ispunct(c, loc);
}
对于您的问题,您还可以执行以下操作:
#include <locale>
#include <string>
#include <algorithm>
#include <functional>
int main()
{
std::wstring word = L"søme.?.thing";
std::locale loc("en_US.UTF-8");
using namespace std::placeholders;
word.erase(std::remove_if(word.begin(), word.end(),
std::bind(std::ispunct<wchar_t>, _1, loc)), word.end());
std::wcout << word << std::endl;
}
相关文章:
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- uint_not_usable_without_attribute在业力规则中使用数字生成器时静态断言失败
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 断言"id < 0"在Qt ActiveX中失败
- 在 CppUnit 中测试中止断言失败
- 使用扫描的调试断言失败
- MS 本机单元测试 - 断言::线程失败不起作用
- 为什么我的Qt程序在断言失败后继续运行?
- 图片不显示,关闭时出错 --> 调试断言失败!表达式:is_block_type_valid(标头>_block_use)
- 访问提升:shared_ptr 主范围外崩溃,断言失败:px != 0.指针的正确用法是什么?
- C++ 调试断言失败 - 矢量下标超出视觉工作室的范围
- 错误:断言失败 (src.type() == CV_8UC1) 在阈值中
- Boost Beast 异步服务器失败,断言失败:(id_ != T::id) 在多个 aync 调用中
- 使用imwrite OpenCV时断言失败
- 调试断言失败的缓冲区!=nullptr
- 使用 ofstream 写入文本文件时断言失败
- OpenCV 错误:相机校准:断言在matrix_wrap.cpp失败
- 提升继续恢复断言失败
- 获取有关调试断言失败的错误:表达式:"(_Ptr_user &(_BIG_ALLOCATION_ALIGNMENT -1)) == 0" &&0
- 打破gdb中失败断言的正确方法是什么