C语言从键盘输入数据
C语言从键盘输入数据
getline()方法
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
string line;
getline(cin, line);
char str[20];
strcpy(str, line.c_str());
cout << line << endl;
system("pause");
return 0;
}
cin方法
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
int value[10];
for (int i = 1; i <= 10; i++) {
cout << "请输入第" << i << "个整数:" << endl;
cin >> value[i - 1];
}
cout << "反序输出:" << endl;
for (int i = 9; i >= 0; i--) {
cout << value[i] << ' ';
}
system("pause");
return 0;
}