首页 第二章 字符串、类函数实例

第二章 字符串、类函数实例

举报
开通vip

第二章 字符串、类函数实例null字符串处理函数字符串处理函数Puts(strs);//strs-字符数组 Gets(strs); Strcpy(str1,const str2); Strcat(str1,str2); Strcmp(str1,str2); Strlen(strs); Strlwr(strs); strUpr(strs);Gets(),puts()使用Gets(),puts()使用#include void main() { char str[200]; gets(str); puts(str); }Strcpy,s...

第二章 字符串、类函数实例
null字符串处理函数字符串处理函数Puts(strs);//strs-字符数组 Gets(strs); Strcpy(str1,const str2); Strcat(str1,str2); Strcmp(str1,str2); Strlen(strs); Strlwr(strs); strUpr(strs);Gets(),puts()使用Gets(),puts()使用#include void main() { char str[200]; gets(str); puts(str); }Strcpy,strcat,strcmpStrcpy,strcat,strcmp#include #include #include void main() { char str1[200],str2[100]; cout<<" Please input a string:(str2) "< void main() { char ch,str2[10]; // cout<<" Please input a char:(ch) "< class Clock {private: int Hour,Minute,Second; public: void SetTime(int nH,int nM,int nS); void ShowTime(); }; void Clock::SetTime(int nH,int nM,int nS) { Hour=nH; Minute=nM; Second=nS;} void Clock::ShowTime() { cout<<"Time "<5) continue;//break; cout<<"\t\taft "< class distance { int mile,yard; public: distance(); distance(int,int); void get_value(); distance add_value(distance A); void display(); }; distance::distance() { mile=0;yard=0; } distance::distance(int m1,int y1) { mile=m1; yard=y1; }nullvoid distance::get_value() { cout<<"Enter mile: "; cin>>mile; cout<<"Enter yard: "; cin>>yard; } distance distance::add_value(distance A) { distance B; B.yard=yard+A.yard; B.mile=0; if(B.yard>=1760) { B.mile=1; B.yard-=1760; } B.mile+=mile+A.mile; return B; } void distance::display() { cout< void main() { int x,y; ifstream inf("e:\\a.txt"); inf>>x>>y; ofstream outf("e:\\b.txt"); outf< main() { char ch; ifstream f1("file_from.txt"); if(!f1) { cout<<"Cannot open 'file_from.txt' for input"< #include #include #include void main() { char date[19],time[9]; _strdate(date); cout< #include void main() { FILE *fp; char ch,filename[1000]; // scanf("%s",filename); if((fp=fopen("abc","r"))==NULL) { printf("cannot open file\n"); exit(0); }null ch=fgetc(fp); int i=0; while(ch!=EOF) { filename[i]=ch; // putchar(ch); ch=fgetc(fp); i++; } fclose(fp); }存结构成员存结构成员#include #define SIZE 4 struct student_type{ char name[10]; int num; int age; char addr[15]; }stud[SIZE];nullvoid save() { FILE *fp; int i; if((fp=fopen("stu_list","wb"))==NULL) { printf("cannot open file\n"); return; } for(i=0;i 内容 财务内部控制制度的内容财务内部控制制度的内容人员招聘与配置的内容项目成本控制的内容消防安全演练内容 1屏幕输出文件内容1#include #include void main() { char ch; ifstream inf("what.txt"); while(!inf.eof()) { inf.get(ch); cout< #include void main() { char fname[30],line[129]; cout<<"INput file name "<>fname; ifstream inf(fname,ios::nocreate); try{ if(inf.fail()) throw fname; }null catch(char *str){ cout<<"cannot open file "< #include void main() { char line[81]; ifstream inf("what.txt"); inf.getline(line,80); while(!inf.eof()) { inf.getline(line,80); cout< check >>t.txt
本文档为【第二章 字符串、类函数实例】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_445021
暂无简介~
格式:ppt
大小:64KB
软件:PowerPoint
页数:0
分类:
上传时间:2012-05-06
浏览量:13