Hello, I am looking to pass the int values of an array to the indices of a string array "behind the scenes." I want the string arrays to be ouput with their strings, however I want to do math on the indices the strings represent.
In other words I would like to combine or blend them together so that I have 4 arrays: 2 of them are int arrays, 1 of the int arrays is for doing math on; and 2 of them are string arrays, both of them are for display to the screen purposes only.
If I try to loop through the int arrays and assign the string array elements to their corresponding indices, it won't compile, and I get the error message:
"Cannot convert 'std::string' to 'int' in assignment."
If I try to loop through the string arrays and assign them the int array values to their corresponding indices, it compiles, however I get the ASCII representation of the int values, rather than the numbers.
Here is the code for looping through the int arrays:
Code:
#include <iostream>
using namespace std;
int main()
{
int typeArray[4] = {55,66,77,88};
int valArray[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
string types[4] = {"Manny", "Moe", "Jack", "John" };
string values[13] = {"One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten",
"Eleven","Twelve","Thirteen"};
for (int i = 0; i < sizeof(typeArray)/sizeof(int); i++)
{
for (int j = 0; j < sizeof(valArray)/sizeof(int); j++)
{
typeArray[i] = types[0];
valArray[j] = values[0];
}
}
system("Pause");
return 0;
}
AGAIN, IT WON'T COMPILE, AND I GET THE ERROR MESSAGE NOTED ABOVE.
Here is the code for looping through the string arrays and the output:
Code:
#include <iostream>
using namespace std;
int main()
{
int typeArray[4] = {55,66,77,88};
int valArray[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
string types[4] = {"Manny", "Moe", "Jack", "John" };
string values[13] = {"One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten",
"Eleven","Twelve","Thirteen"};
for (int i = 0; i < sizeof(types)/sizeof(int); i++)
{
for (int j = 0; j < sizeof(values)/sizeof(int); j++)
{
types[i] = typeArray[0];
values[j] = valArray[0];
cout << "This is types array: " << types[i] << " This is values array: " << values[j] << endl;
}
}
system("Pause");
return 0;
}
------------------------
HERE IS THE OUTPUT SHOWING ASCII CONVERSIONS OF THE INTS:
This is types array: 7 This is values array: ☺
--------------------
Please advise, thanks!