Pretty simple c++ question here, how do I replace part of variable reference with another variable, almost to concatenate it.
For example I have a structure with item1
, item2
, item3
, I ask the user what Item they want the information of which is stored in a variable itemNo
for example:
cout << "The item you selected is " << item(itemNo).name;
if itemNo==1
the reference would need to become item1.name
;
Brackets is wrong in this scenario, but what is the right way to insert a number to form the right variable reference?