isspace函数的debug版本处理中文程序异常

在Visual Studio 2008环境下,遇到使用isspace函数处理中文字符时出现程序异常的情况。这个问题可能涉及到C++标准库在处理宽字符和多字节字符集时的兼容性问题。解决此类问题通常需要理解Unicode和MBCS在Windows平台的交互,并可能需要自定义函数来正确处理中文字符。
摘要由CSDN通过智能技术生成

开发环境 :VS2008


示例代码:

#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <functional>
#include <locale>
#include <cctype>

using namespace std;

inline string& ltrim(string &str) {  
	string::iterator p = find_if(str.begin(), str.end(), std::not1(ptr_fun<int, int>(isspace)));  
	str.erase(str.begin(), p);  
	return str;  
}  

inline string& rtrim(string &str) {  
	string::reverse_iterator p = find_if(str.rbegin(), str.rend(), std::not1(ptr_fun<int , int>(isspace)));  
	str.erase(p.base(), str.end());  
	return str;  
}  

inline string& trim(string &str) {  
	ltrim(rtrim(str));  
	return str;  
}  

int main(){

	#if _DEBUG
	setlocale(LC_ALL, "chs");
	#endif
	
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值