提问人:AZERUL BIN BADRUL ISHAM 提问时间:11/7/2021 更新时间:11/7/2021 访问量:49
C++ 如何传递此特定代码的引用?
C++ How to pass reference for this specific code?
问:
请考虑以下几点:
void sum(vector<string> arr[], vector<string> columnName)
{
int n, *sum = 0;
cout << "Enter column number to calculate : ";
cin >> n;
cin.ignore(80, '\n');
cout << columnName[n-1] << endl;
for (auto item=arr[n-1].begin(); item!=arr[n-1].end(); item++)
{
if (item[0] == "1")
{
for (int i=1; i<sizeof(item[n-1]); i++)
{
// cout << item[i] << " ";
sum += stoi(item[i]); //how to reference this(the sum im talking about)
cout << sum << " ";
}
cout << sum << endl; // to become value of sum outside of the block here
}
else
if (item[0] == "0")
{
cout << "Column can not be calculated" << endl;
break;
}
}
// return sum;
}
包含以下数据:
7
id,age,math,science,malay,chem,bio
0, 1, 1, 1, 1, 1, 1
5
1201101210,19,95,98,97,90,88
1201101490,12,87,100,92,100,70
1201101154,40,98,72,78,81,94
1201101376,23,40,50,70,79,100
1201101987,36,85,73,74,66,59
有一个带有局部变量的总和,我在注释中突出显示了它,我想将该总和从块中带到下面的块中(又名使局部变量全局)。我认为这可以通过使用引用传递来实现,但我不确定如何:(
答: 暂无答案
评论
sum
int n, *sum = 0;
sizeof(item[n-1])
sum