把工程改为Unicode的 来查看Unicode的txt文件 取出每一行的汉字
来源:互联网 发布:数据新闻报道比赛 编辑:程序博客网 时间:2024/05/03 05:08
(1)把 Preprocessor Definitiond 写入UNICODE,_UNICODE (要选择一下默认的值这样才能改的生效)
(2)工程改成Unicode的
#ifdef _UNICODE
#define tstring std::wstring
#else
#define tstring std::string
#endif
实现过程:
readtxt.cpp:
#include "stdafx.h"
#include <stdio.h>
#include<fstream>
using namespace std;
tstring getline(FILE *stream)
{
tstring strRet;
TCHAR line[100] = {0};
while( _fgetts( line, 100, stream ) != NULL)
{
if (line[0] == 0xFEFF) //unicode 文件的头
{
strRet += &line[1];
}
else
{
strRet += line;
}
if (line[_tcslen(line)-1] == _T('\n'))
{
break;
}
}
return strRet;
}
void Trim( tstring& str , const tstring& chars =_T(" \t" ))
{
str.erase(str.find_last_not_of(chars)+1);
str.erase(0, str.find_first_not_of(chars));
}
int main(int argc,char **argv)
{
FILE *stream = NULL;
TCHAR szUserSuffix [20] = _T("E:\\1.txt");
TCHAR strQuickUser[100]={0};
if( _wfopen_s( &stream,strQuickUser, _T("rt+,ccs=UNICODE ") ) == 0 ) //用到的函数都是多字节的;
{
tstring sRead;
while (!feof(stream))
{
sRead = getline(stream);
if (sRead.empty())
{
continue;
}
else
{
int n;
n=sRead.find(_T("="));
tstring s1 = _T("");
tstring s2 = _T("");
s1=sRead.substr(0,n);
s2=sRead.substr(n+1,sRead.length());
Trim(s1);
Trim(s2);
TCHAR tstrInitial[200];
TCHAR tstrChinese[200];
TCHAR tstrEspecial[200];
bool flag = false;
_tcscpy(tstrInitial ,s2.c_str());
int j =0;
for(int i=0; i<s2.length(); i++)
{
if ((tstrInitial[i]>=0x4E00)&&(tstrInitial[i]<=0x9FA5))
{
tstrChinese[j] = tstrInitial[i] ;
tstrChinese[++j] = tstrInitial[++i]; //汉字
j++;
flag = true;
}
else
{
if (flag==true)
{
break;
}
else
{
;
}
}
}
tstrChinese;
}
}
- 把工程改为Unicode的 来查看Unicode的txt文件 取出每一行的汉字
- Java:把汉字为unicode形式的字符串和把unicode字符串转换成汉字
- 汉字的Unicode编码
- 汉字的Unicode 内码
- 汉字的unicode范围
- 读写Unicode带中文的txt文件
- Unicode汉字、英文字母、数字的unicode范围
- MFC 在非unicode的工程下,读取unicode编码的txt
- 获得汉字的unicode编码
- Unicode转汉字的实现
- 输出汉字的Unicode值
- 汉字的unicode码范围
- c++汉字的unicode码
- 汉字转unicode的方法
- 常用汉字的unicode编码
- 常用汉字的unicode 编码
- 常用汉字的unicode编码
- 汉字转unicode的方法
- MSP430F5438 定时器总结
- Shell比较两个日期的大小
- 聚类分析软件操作流程
- Java异常处理总结
- Flex 下载服务器上的文件
- 把工程改为Unicode的 来查看Unicode的txt文件 取出每一行的汉字
- 关于ios发布AppStore验证UUID不过的问题
- WinCE上BINFS实现详解
- Video Composition With iOS
- 对DllRegisterServer的调用失败,错误代码为0x80070005
- ARM架构
- IE安全选项对应的注册表值
- SQL注入漏洞全接触--入门篇
- MacOS 开机自动加载 SVNSERVE 服务