📄 upperch.cpp
字号:
//这个程序在本书所带软盘中。文件名为UPPERCH.CPP
//这个程序利用cin.getline()进行字符串输入,并将输入的字母转换为大写。
#include <iostream.h>
#include <stdio.h> //这个头文件支持puts()
#include <string.h> //这个头文件支持strlen()
#include <conio.h> //这个头文件支持getche()
#include <ctype.h> //这个头文件支持toupper()
#include <stdlib.h> //这个头文件支持exit()
#define thanks "\n谢谢你再次使用这个程序!\n"
void main(void)
{
char text[81]; //定义字符串
while (1) {
cout << "请输入一行字符串:";
cin.getline(text, sizeof(text));
//strlen()返回字符串的实际长度
for (int i = 0; i < strlen(text); i++)
text[i] = toupper(text[i]);
puts(text);
cout << "你想继续程序运行吗?(y/n): ";
if (toupper(getche()) == 'N') {
cout << thanks;
exit(1);
}
}
}
/*这个程序运行后将显示如下输出结果:
请输入一行字符串:This is a line of string.
THIS IS A LINE OF STRING.
你想继续程序运行吗?(y/n): y
请输入一行字符串:This is the second line.
THIS IS THE SECOND LINE.
你想继续程序运行吗?(y/n): n
谢谢你再次使用这个程序!
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -