Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Sat Aug 27, 2016 12:37 am Post subject: Some questions about Visual C++, arrays and map. |
|
|
I want to make a form like the one on the screenshot. When the user selects a name in the comboBox, three values, which are attack, defense, intelligence, will appear in the three textBoxes on the right. I do not want to use "comboBox->SelectedIndex" instead of "comboBox->Text".
Therefore, here is my plan:
1. Use map in C++ to associate each names(string) with an integer. For example, Michael with 0, James with 2, Bob with 1(different than the order that appears on the comboBox drop down list) :
Code: |
std::map<std::string, int> players;
players["Michael"] = 0;
players["Bob"] = 1;
players["James"] = 2;
|
2. Create an array to store the three values with the names. For example,
Code: |
int data[][2] ={
{15, 15, 15}, //Michael
{30, 25, 5}, //Bob
{10, 10, 30}, //James
....................
}
|
3. Check the text in the comboBox, then get the corresponding values:
Code: |
//The combobox selection change event:
textBox1->Text == data[players[comboBox1->Text]][0]; //attack
textBox2->Text == data[players[comboBox1->Text]][1];//defense
textBox3->Text == data[players[comboBox1->Text]][2];//intelligence
|
So, my questions are:
1. Will this work?
2. If so, where should I declare and define the array and map? I had run into some problems with this issue. I was using C++ window form on Visual Studio 2015. All the events are automatically generated in the header file. I declared and defined the map and array in the form class, but they could not be used in the event function, like they were not activated.
I hope my explanation is not very confusing.
Thanks in advance.
Description: |
|
Filesize: |
19.44 KB |
Viewed: |
3166 Time(s) |

|
|
|