I have created two arrays, friends and timechat. Instead of writing long code that manually puts each piece of data into the 2d array I want to do it with a for loop. I have created a 2D array, 2 columns and 5 rows. One column must have all the names of the friends the other the times. Where am I going wrong?
Code:
string **friendslist;
friendslist = new string*[10];
for (int i = 0; i < 10; i++)
friendslist[i] = new string[10];
string friends[5] = {"Bob","Rob","Jim","Hannah","James"};
string timechat[5] = {"12:00", "5:00", "22:00", "18:30", "11:45"};
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 2; j++)
{
friendslist[j][i] = friends[i];
cout << friendslist[j][i] << " ";
}
cout << endl;
}
cin.get();
std::array
(orstd::vector
) withstd::string
?y
counter that is not referenced within. Is this the dead husk of a previous iteration of the code? It only obfuscates the problem.for
loops that count from 0 to 0. (for int j = ...
)