首先完整代码如下:
#include <iostream> #include <string> using namespace std; int main() { int oneInt1, oneInt2; char strArray[20]; string str; double oneDouble; char oneChar = 'a'; cout << "输入两个整型值,一个字符,一个字符串和一个浮点值,"; cout << "以空格,Tab键或<Enter>键分割:" << endl; cin >> oneInt1 >> oneInt2 >> oneChar >> strArray >> oneDouble; str = strArray; cout << "输入的数据是:"<<endl; cout << "字符串是:\t\t" << str << endl << "两个整型值分别是:\t" << oneInt1 << "和\t" << oneInt2 << endl << "字符是:\t\t" << oneChar << "\n" << "浮点值是:\t\t" << oneDouble << endl; return 0; }
该程序是一个数据类型分类的小程序
1.该语句是为了定义两个整型变量:
int oneInt1, oneInt2;
2.该语句定义了 20个下标名为strArray字符串数组:
char strArray[20];
3.定义了一个名为str的 string 对象,长度为 0:
string str;
4.定义一个浮点型变量:
double oneDouble;
5.定义一个字符:
char oneChar = 'a';
6.输出提示:
cout << "输入两个整型值,一个字符,一个字符串和一个浮点值,"; cout << "以空格,Tab键或<Enter>键分割:" << endl;
7.输入:
cin >> oneInt1 >> oneInt2 >> oneChar >> strArray >> oneDouble;
8.将strArray的值赋予str:
str = strArray;
9.输出结果:
cout << "输入的数据是:"<<endl; cout << "字符串是:\t\t" << str << endl << "两个整型值分别是:\t" << oneInt1 << "和\t" << oneInt2 << endl << "字符是:\t\t" << oneChar << "\n" << "浮点值是:\t\t" << oneDouble << endl;