1.字符函数库cctype
2.简单文件输入/输出
coutfixed//用一般的方式输出浮点型,例如C++程序在控制台显示的时候大一点的数,显示的时候使用了科学计数法,使用该命令即可像一般的方式显示cout.precision(2)//设置精确度为2,并返回上一次的设置。cout.setf(iOS_base::showpoint)//显示浮点数小数点后面的零。3.练习
/******************************************************编写一个程序,它打开一个文本文件,逐个字符地读取该文件,直到到达文件末尾,然后指出该文件中包含多少个字符*******************************************************/#includeiostream#includefstream#includecstdlibconstintSIZE=60;intmain(){usingnamespacestd;charfilename[SIZE];ifstreaminfile;cout"请输入带读取文件的文件名:";cin.getline(filename,SIZE);infile.open(filename);if(!infile.is_open()){cout"打开文件失败!!1"endl;cout"进程正在结束..."endl;exit(EXIT_FAILURE);}chardata;intcount=0;infiledata;while(infile.good()){++count;coutdata;infiledata;}coutendl;if(infile.eof())cout"文件读取完毕。"endl;elseif(infile.fail())cout"数据类型不匹配"endl;elsecout"发生未知错误,读取终止。"endl;cout"文件字符数量为"countendl;infile.close();system("pause");return0;}
/****************************************************************编写一个程序,记录捐助给“维护合法权利团体”的资金。该程序要求用户输入捐献者数目,然后要求用户输入每一个捐献者的姓名和款项。这些信息被储存在一个动态分配的结构数组中。每个结构有两个成员:用来储存姓名的字符数组(或string对象)和用来储存款项的double成员。读取所有的数据后,程序将显示所有捐款超过的捐款者的姓名及其捐款数额。该列表前应包含一个标题,指出下面的捐款者是重要捐款人(GrandPatrons)。然后,程序将列出其他的捐款者,该列表要以Patrons开头。如果某种类别没有捐款者,则程序将打印单词“none”。该程序只显示这两种类别,而不进行排序。*****************************************************************/#includeiostream#includestringusingnamespacestd;structpatrons{stringname;doublemoney;};intmain(){cout"请输入捐款者总人数:";intnumber,temp1,temp2;number=temp1=temp2=0;cinnumber;patrons*ps=newpatrons[number];for(inti=0;inumber;++i){cout"请输入第"i+1"个捐赠者的姓名:";cinps[i].name;cout"请输入捐赠金额:";cinps[i].money;}cout"GRANDPATRONS"endl;for(inti=0;inumber;++i){if(ps[i].money){coutps[i].name"\t"ps[i].moneyendl;++temp1;}}if(temp1==0)cout"none"endl;cout"PATRONS"endl;for(inti=0;inumber;++i){if(ps[i].money=){coutps[i].name"\t"ps[i].moneyendl;++temp2;}}if(temp1==0)cout"none"endl;delete[]ps;system("pause");return0;}