C++的一些代码——用键盘接收数据

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;
}

猜你喜欢

转载自blog.csdn.net/qq_32651847/article/details/113844006