我有以下代码。
// 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;
}
Run Code Online (Sandbox Code Playgroud)
对于第一个消息框,
我的腿长
将被显示。
对于第二个消息框,会发生崩溃,并在 isctype.c 处断言失败
_ASSERTE((unsigned)(c + 1) <= 256);
Run Code Online (Sandbox Code Playgroud)
我如何获得标准函数(isdigit、isspace...)来支持 256 范围以外的 unicode?
| 归档时间: |
|
| 查看次数: |
6725 次 |
| 最近记录: |