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

原文地址:https://www.cnblogs.com/xpylovely/p/11187104.html