函数名称 | 返回值 |
|---|---|
isalnum() | 如果参数是字母数字,即字母或者数字,该函数返回值为true |
isalpha() | 如果参数是字母,该函数返回true |
iscntrl() | 如果参数是控制字符,该函数返回true |
isdigit() | 如果参数是数字(0-9),该函数返回true |
isgraph() | 如果参数是除空格之外的打印字符,该函数返回true |
islower() | 如果参数是小写字母,该函数返回true |
isprint() | 如果参数是打印字符(包括空格),该函数返回true |
ispunct() | 如果参数是标点符号,该函数返回true |
isspace() | 如果参数是标准空白字符,如空格、进制、换行符、回车、水平制表符或者垂直制表符,该函数返回true |
isupper() | 如果参数是大写字母,该函数返回true |
isxdigit() | 如果参数是十六进制数字,即0-9、a-f或者A-F,该函数返回true |
tolower() | 如果参数是大写字符,则返回其小写,否则返回该参数 |
toupper() | 如果是小写字符,则返回其小写,否则返回该参数 |
cout<<fixed //用一般的方式输出浮点型,例如C++程序在控制台显示的时候大一点的数,显示的时候使用了科学计数法,使用该命令即可像一般的方式显示
cout.precision(2) //设置精确度为2,并返回上一次的设置。
cout.setf(iOS_base::showpoint) //显示浮点数小数点后面的零。
1.编写一个程序,它打开一个文本文件,逐个字符地读取该文件,直到到达文件末尾,然后指出该文件中包含多少个字符。
#include<iostream>
#include<fstream>
#include<cstdlib>
const int SIZE = 60;
int main()
{
using namespace std;
char filename[SIZE];
ifstream infile;
cout << "请输入带读取文件的文件名:";
cin.getline(filename,SIZE);
infile.open(filename);
if (!infile.is_open())
{
cout << "打开文件失败!!1" << endl;
cout << "进程正在结束..." << endl;
exit(EXIT_FAILURE);
}
char data;
int count = 0;
infile >> data;
while (infile.good())
{
++count;
cout << data;
infile >> data;
}
cout << endl;
if (infile.eof())
cout << "文件读取完毕。" << endl;
else if (infile.fail())
cout << "数据类型不匹配" << endl;
else
cout << "发生未知错误,读取终止。" << endl;
cout << "文件字符数量为" << count << endl;
infile.close();
system("pause");
return 0;
}
2.编写一个程序,记录捐助给“维护合法权利团体”的资金。该程序要求用户输入捐献者数目,然后要求用户输入每一个捐献者的姓名和款项。这些信息被储存在一个动态分配的结构数组中。每个结构有两个成员:用来储存姓名的字符数组(或string对象)和用来储存款项的double成员。读取所有的数据后,程序将显示所有捐款超过10000的捐款者的姓名及其捐款数额。该列表前应包含一个标题,指出下面的捐款者是重要捐款人(Grand Patrons)。然后,程序将列出其他的捐款者,该列表要以Patrons开头。如果某种类别没有捐款者,则程序将打印单词“none”。该程序只显示这两种类别,而不进行排序。
#include<iostream>
#include<string>
using namespace std;
struct patrons
{
string name;
double money;
};
int main()
{
cout << "请输入捐款者总人数: ";
int number, temp1, temp2;
number=temp1=temp2=0;
cin >> number;
patrons *ps = new patrons[number];
for (int i = 0; i < number; ++i)
{
cout << "请输入第" << i + 1 << "个捐赠者的姓名: ";
cin >> ps[i].name;
cout << "请输入捐赠金额: ";
cin >> ps[i].money;
}
cout << "GRAND PATRONS" << endl;
for (int i = 0;i < number; ++i)
{
if (ps[i].money > 10000)
{
cout << ps[i].name <<"\t" << ps[i].money << endl;
++temp1;
}
}
if (temp1 == 0)
cout << "none" << endl;
cout << "PATRONS" << endl;
for (int i = 0; i < number; ++i)
{
if (ps[i].money <= 10000)
{
cout << ps[i].name << "\t" << ps[i].money << endl;
++temp2;
}
}
if (temp1 == 0)
cout << "none" << endl;
delete[]ps;
system("pause");
return 0;
}