现在的位置: 首页 > 综合 > 正文

primer第五版5.9第六题

2018年02月20日 ⁄ 综合 ⁄ 共 656字 ⁄ 字号 评论关闭
/*2014,1.09  Arby*/
/*C++ primer 5.9practise of codding*/
/*主要设计到交替读取数值和字符串的输入时应该注意的一些东西*/

#include <iostream>
using namespace std;

const int char_size = 20;
struct information
{
	char producer[char_size];
	int produce_year;
};

int main()
{	
	int number = 0;
	cout << "please enter the number of you want to get:" << endl;
	cin >> number;
	cin.get();        /*输入字符串之前要进行先清除换行符*/

	/*new the number of information*/
	information *custom = new information[number];
	for(int i = 0; i < number; i++)
	{
		cout << "enter the producer :";
		cin.get(custom[i].producer, char_size);
		cin.get();
		cout << "enter the year: ";
		cin >> custom[i].produce_year;
		cin.get();
	}
	for(int j = 0; j < number; j++)
		cout << custom[j].produce_year << "  " << custom[j].producer << endl;
	
	cin.get();
	cin.get();
	return 0;
} 

抱歉!评论已关闭.