zoukankan      html  css  js  c++  java
  • C++从键盘读入数组并存储

    C++从键盘读取任意长度的数组,现总结如下:

    //读取指定长度的数组
    int main()
    {
    	int n = 0;
    	cin >> n;
    	vector<int> p(n);
    	for (int i = 0; i < n; i++) {
    		cin >> p[i];
    	}
    
    	for (int i = 0;i < p.size();i++)
    	{
    		cout << p[i];
    	}
    	cout << endl;
    	system("pause");
    }
    
    //从键盘读入任意长度的数组
    int main()
    {
    	vector<int>nums;
    	int num = 0;
    	do {
    		cin >> num;
    		nums.push_back(num);
    	} while (getchar() != '
    ');
    
    	for (int i = 0;i < nums.size();i++)
    	{
    		cout << nums[i];
    	}
    	cout << endl;
    	system("pause");
    	return 0;
    }
    
    //键盘输入字符串类型的整数,然后将其输出数组中
    int main()
    {
    	string str, temp;
    	getline(cin, str);
    	int i = 0;
    	vector<int> p;
    	stringstream input(str);
    	while (input >> i) {
    		p.push_back(i);
    	}
    	for (int i = 0;i < p.size();i++)
    	{
    		cout << p[i];
    	}
    	cout << endl;
    	system("pause");
    	return 0;
    }
    

      

  • 相关阅读:
    https://github.com/cykl/infoqscraper/
    C# 笔记
    json.org
    python html parse
    doxygen
    review board
    ruunlevel debian
    连接REDIS
    composer
    php需要注意的地方
  • 原文地址:https://www.cnblogs.com/zhuruibi/p/9458107.html
Copyright © 2011-2022 走看看