1, press a character to terminate the input
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
char c;//声明变量c
c=getch();//输入变量c
cout<<c;//输出变量c
return 0;
}
input: c
output: c
2, press an input to terminate the input
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
int c;//声明变量c
c=getch()//输入变量c
c=c-48//此时c存储的是输入字符的ascll码现在将它转换为数字
Example 1 | Example 2 |
Input: 2 (ascll: 50) | Input: A (ascll:65) |
Output: 2 | Output: 17 |