gpt4 book ai didi

c++ - Unicode 支持的 isdigit 和 isspace 函数

转载 作者:行者123 更新时间:2023-11-30 01:31:23 31 4
gpt4 key购买 nike

我有以下代码。

// mfc.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "mfc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include <cctype>
#include <string>
#include <sstream>
#include <tchar.h>
#include <iostream>
#include <Strsafe.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <functional>
#include <cassert>

std::wstring toStringWithoutNumerical(const std::wstring& str) {
std::wstring result;

bool alreadyAppendSpace = false;
for (int i = 0, length = str.length(); i < length; i++) {
const TCHAR c = str.at(i);
if (isdigit(c)) {
continue;
}
if (isspace(c)) {
if (false == alreadyAppendSpace) {
result.append(1, c);
alreadyAppendSpace = true;
}
continue;
}
result.append(1, c);
alreadyAppendSpace = false;
}

return result;
}


// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
}

std::wstring me = toStringWithoutNumerical(_T("My Leg 1 Long"));
AfxMessageBox(me.c_str());

// Crash!
std::wstring he = toStringWithoutNumerical(L"我的脚1盘");
AfxMessageBox(he.c_str());

return nRetCode;
}

对于第一个消息框,

我的腿长

将显示。

对于第二个消息框,将发生崩溃,断言在 isctype.c 处失败

_ASSERTE((unsigned)(c + 1) <= 256);

如何获得标准函数(isdigit、isspace...)以支持 256 范围外的 unicode?

最佳答案

关于c++ - Unicode 支持的 isdigit 和 isspace 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3108282/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com