⑴ 在c语言环境下检索汉字文本程序
#include<iostream>
#include<numeric>
#include<fstream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
#include<stack>
#include<queue>
#include<utility>
#include<sstream>
#include<iterator>
#include<map>
#include<windows.h>
using namespace std;
void display();
void password(int nu);
void jiequ();
void shuoming();
void main()
{
system("color 0e");
cout<<endl;
cout<<"小说文块截取器"<<endl;
cout<<endl;
cout<<"程序自我检测启动!"<<endl;
cout<<endl;
cout<<"Checking.........."<<endl;
cout<<endl;
Sleep(3000);
cout<<"已确认无资料丢失,允许安全保护模块介入........"<<endl;
Sleep(1000);
password(1);
}
void password(int nu)
{
system("cls");
cout<<endl;
if(4-nu==0)
{
cout<<endl;
cout<<"三次输入错误,强制退出!!!"<<endl;
cout<<endl;
system("pause");
}else{
cout<<"请输入程序启动密码(1q2w3e):"<<endl;
string PASSWORD;
cin>>PASSWORD;
if(PASSWORD=="1q2w3e")
{
display();
}else{
++nu;
cout<<endl;
cout<<"密码错误!请重新输入!!你还剩下"<<4-nu<<"次机会"<<endl;
cout<<endl;
system("pause");
password(nu);
}
}
}
void display()
{
system("cls");
cout<<endl;
cout<<"----小说文块截取器 (MP4专用)----"<<endl;
cout<<endl;
cout<<"--------------------------------"<<endl;
cout<<endl<<endl;
cout<<" 1.开始截取"<<endl<<endl;
cout<<" 2.程序说明"<<endl<<endl;
cout<<" 3.退出程序"<<endl<<endl;
cout<<endl;
cout<<"---------------------------------"<<endl;
cout<<"请选择:"<<flush;
string xuan;
cin>>xuan;
if(xuan!="1"&&xuan!="2"&&xuan!="3")
{
cout<<endl;
cout<<"不存在此选项!"<<endl;
system("pause");
display();
}else{
if(xuan=="1")
{
jiequ();
}
if(xuan=="2")
{
shuoming();
}
if(xuan=="3")
{
//退出模块
}
}
}
void jiequ()
{
system("cls");
cout<<endl;
cout<<" 初用者必读"<<endl;
cout<<endl;
cout<<"请先在小说(文章)里要开始截的地方做一个标志,再到结束截的地方做一个标志"<<endl;
cout<<endl;
cout<<"例如在小说开头输入一个AB,再到100章那里开头输入BC,并将其保存,"<<endl;
cout<<endl;
cout<<"直接在标题那行添加!避免标志被忽略!"<<endl;
cout<<endl;
cout<<"程序将在全文中寻找这两个标志,并将其括起并进行截取,"<<endl;
cout<<endl;
cout<<"程序不会对原文件进行任何修改,但为安全起见,还请先备份!"<<endl;
cout<<endl;
cout<<"本程序不接受任何中文输入,请自行把文件名改为英文!"<<endl;
cout<<endl;
cout<<"本程序默认路径为程序所在目录路径,使用者可把文件放在与本程序同一目录,"<<endl;
cout<<endl;
cout<<"这样输入路径处直接输入文件名即可(切记要连后缀一起输入)!"<<endl;
cout<<endl;
system("pause");
system("cls");
cout<<endl;
cout<<"截取模块进入成功!"<<endl;
cout<<endl;
cout<<"请输入开始标志:"<<endl;
string beg;
cin>>beg;
cout<<"请输入结束标志:"<<endl;
string end;
cin>>end;
cout<<"请输入要截取的源文件路径(默认为当前程序目录):"<<endl;
string way;
cin>>way;
cout<<"请输入截取后的文件输出路径(默认为当前程序目录):"<<endl;
string way_go_zhu;
cin>>way_go_zhu;
system("cls");
cout<<endl;
cout<<"开始标志为"<<beg<<endl;
cout<<"结束标志为"<<end<<endl;
cout<<endl;
cout<<endl;
cout<<"正在读入资料..............."<<endl;
ifstream way_open(way.c_str());
if(!way_open)
{
cout<<endl;
cout<<"找不到文件!路径错误!!!"<<endl;
cout<<endl;
cout<<"返回菜单............."<<endl;
cout<<endl;
system("pause");
system("cls");
display();
}else{
vector<string> word_save;
string word;
while(way_open>>word)
{
word_save.push_back(word);
}
cout<<"读入完成."<<endl;
int kai=0,jieshu=0;
int kai_save=0,jieshu_save=0;
cout<<"正在进行截取.............."<<endl;
int OK=0;
for(vector<string>::iterator l=word_save.begin();l!=word_save.end();++l)
{
if(beg==(*l))
{
cout<<"已找到开始标志!"<<endl;
kai_save=kai;
++OK;
}
if(end==(*l))
{
cout<<"已找到结束标志!"<<endl;
jieshu_save=jieshu;
++OK;
}
++kai;
++jieshu;
}
if(OK!=2)
{
cout<<endl;
cout<<"无法找到开始(结束)标志,请检查标志是否独立存在,标志前后只能是空格!~"<<endl;
cout<<endl;
cout<<"请直接在题目或文章中添加标志保存即可!"<<endl;
cout<<endl;
cout<<"截取出现错误~~~~! 返回菜单............"<<endl;
cout<<endl;
system("pause");
display();
}else{
cout<<"截取完毕."<<endl;
cout<<endl;
ofstream zz(way_go_zhu.c_str());
cout<<endl;
cout<<"正在对文件进行资料注入............."<<endl;
int biao=0;
for(vector<string>::iterator a=word_save.begin();a!=word_save.end();++a)
{
if(biao>=kai_save&&biao<=jieshu_save)
{
zz<<*a<<endl;
}
++biao;
}
cout<<"资料注入完毕."<<endl;
cout<<"开始关闭数据流........"<<endl;
way_open.close();
way_open.clear();
zz.close();
zz.clear();
cout<<"数据流关闭完成."<<endl;
cout<<endl;
cout<<"返回菜单............"<<endl;
cout<<endl;
system("pause");
display();
}
}
}
void shuoming()
{
system("cls");
cout<<endl;
cout<<"本程序由虾味千层糕独立制作完成!"<<endl<<endl;
cout<<"虾味千层糕QQ: 435952144"<<endl;
cout<<" 381426068"<<endl;
cout<<endl;
system("pause");
display();
}
⑵ C语言编程如何查找字符串中指定汉字
用数组比较方便,已兔字符为基准,前移两个找到个数,后移三个找到颜色
⑶ C语言判断汉字
#include<stdio.h>
intmain()
{inti;
unsignedchars[200];
scanf("%s",s);
for(i=0;s[i];i++)
if(s[i]>127)
{printf("汉字");
i++;
}
elseprintf("字母");
return0;
}
(3)c语言汉字查找扩展阅读
C++利用汉字的ASCII编码小于0的特性判断汉字
//coding:utf-8
#include"stdio.h"
intmain()
{
constchar*str="ENG汉字测试ddd";
for(inti=0;str[i]!='