vector auto

#include <iostream>
#include <vector>
#include <string>
using namespace std;
using std::vector;
int main()
{
vector<string> arr;
string str;

vector<int> num;
int a;


while (1)
{
cin >> str;
if (str == "q")
break;
arr.push_back(str);
//cout << str << endl;
}

while (1)
{
cin >> a;
if (a == 0)
break;
num.push_back(a);
}

for (auto i : num)//这里不使用引用,值不变
i *= i;
for (auto i : num)
cout << i << " ";

for (auto &i : num)//使用引用本来的值改变
{
i *= i;
cout << i << " ";
}


for (auto &i : arr)
cout << i << " ";
return 0;
}

posted @ 2019-07-15 09:38  MoonXu  阅读(419)  评论(0编辑  收藏  举报