用输出半角和全角字符
来源:互联网 发布:js 手机号验证 编辑:程序博客网 时间:2024/06/05 16:38
#include <stdio.h>#include <string.h>int main() { char szText[] = "我是CIW."; char szChinese[3] = {0}; int i = 0, nLen = strlen(szText); for(; i < nLen; i++) { if( szText[i] >= 0 && szText[i] <= 127 ) //不是全角字符?{printf("%c\n", szText[i]); }else//是全角字符 {szChinese[0] = szText[i];szChinese[1] = szText[i + 1];printf("%s\n", szChinese);i++;//中文是2个字节,所以i++ }} return 0; }
计算文件大小
#include <sys/types.h> #include <sys/stat.h> #include <iostream.h>#include <string>using namespace std;int getFileSize(string sFileName){ struct stat buf; int iRet = stat(sFileName.c_str(), &buf); if (iRet == -1) return NULL; return buf.st_size;}void main(){int i = getFileSize("E:\\反恐精英csV1.6中文版.exe");cout<<i<<endl;}
去除字符串空格 反转字符串
#include<iostream>#include<string>using namespace std;void strallcut(char *str){ int i,j=0; char sp[512]; for (i = 0; *(str + i) != '\0'; i++) { if (*(str + i) == ' ' ) continue; sp[j++]=*(str + i); } sp[j] = 0; strcpy(str, sp);} void reverse(char s[]){for(int i=0,j=strlen(s)-1;i<j;++i,--j){int c = s[i];s[i] = s[j];s[j] = c;}}void main(){char temp[100] = " hello zhangsan word ";cout<<temp<<endl;strallcut(temp);cout<<temp<<endl;reverse(temp);cout<<temp<<endl;}
统计文档中单词出现的次数
#include <iostream>#include <fstream>#include <string>#include <cstdlib>#include <map>using namespace std;void main(){ifstream read;typedef map<string,int> instrmap;instrmap coll;map<string,int>::iterator it1;ofstream display("word.txt");read.open("words.txt");coll.clear();while(!read.eof()){string word;read>>word;coll[word]++;}for(it1 = coll.begin();it1 != coll.end();it1++)cout<<it1->first<<" "<<it1->second<<endl;if (!display){cout<<"不能打开文件 word.txt"<<endl;}for(it1 = coll.begin();it1 != coll.end();it1++){if (it1->first!="the"&&it1->first!="an"&&it1->first!="a"&&it1->first!="but"&&it1->first!="and"&&it1->first!=" "){display<<"单词"<<it1->first<<" "<<"出现了"<<it1->second<<"次"<<endl;}}read.close();display.close();}
0 0
- 用输出半角和全角字符
- 全角字符和半角字符
- 全角字符和半角字符
- 全角和半角字符转换
- 全角字符转换为半角,判断半角和全角
- 全角字符 半角字符
- 如何区分半角和全角字符
- 运行命令 和 字符全角半角
- 全角 半角 字符 数字
- 去除全角半角字符
- 对于字符串中全角字符和半角字符的判断
- 全角字符和半角字符之间的转换
- MySQL存全角字符和半角字符的区别
- 全角字符变半角字符
- 全角字符转半角字符
- 全角字符转半角字符
- 全角和半角
- 什么是全角和半角
- ThoughtWorks开源了Go持续交付平台
- Struts常见问题
- n对括号匹配的种类
- java 锁的类型和性质(二):自旋锁的其它种类
- 通过HttpURLConnection模拟post表单提交
- 用输出半角和全角字符
- Android imageView 在使用animation时的位置详解
- Unity3D研究院之在Unity中打开第三方数据库配合Android开发(转)
- Fragment Transaction 和 状态丢失 state loss
- 树的遍历转化实现
- poj1694
- 【COGS】1595 [USACO FEB05]神秘的挤奶机 二分最大流
- 从一道面试题谈linux下fork的运行机制
- Java基础-泛型和包装类的语法糖