#include <iostream>
int main() {
char mychar{ 'a' };
int myint{ 123 };
double mydouble{ 456.78 };
std::cout << "The value of a char variable is: " << mychar << '\n';
std::cout << "The value of an int variable is: " << myint << '\n';
std::cout << "The value of a double variable is: " << mydouble << '\n';
return 0;
}
5、编写一个程序,从标准输入接收一个整数,然后打印该整数。
#include <iostream>
int main() {
std::cout << "Please enter a number: ";
int x;
std::cin >> x;
std::cout << "You entered: " << x;
return 0;
}
6、编写一个程序,从标准输入接收两个整数,然后将它们输出。
#include <iostream>
int main() {
std::cout << "Please enter two integer numbers: ";
int x;
int y;
std::cin >> x >> y;
std::cout << "You entered: " << x << " and " << y;
return 0;
}
7、编写一个程序,从标准输入分别接受一个 char 类型、一个 int 类型和一个 double 类型的值,然后将这些值输出。
#include <iostream>
int main() {
std::cout << "Please enter a char, an int and a double: ";
char c;
int x;
double d;
std::cin >> c >> x >> d;
std::cout << "You entered: " << c << ", " << x << ", and " << d;
return 0;
}