Click here to Skip to main content
15,888,816 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Complex multidimensional array in C++ Pin
Richard MacCutchan19-Jan-19 22:14
mveRichard MacCutchan19-Jan-19 22:14 
GeneralRe: Complex multidimensional array in C++ Pin
Daniel Pfeffer19-Jan-19 22:17
professionalDaniel Pfeffer19-Jan-19 22:17 
GeneralRe: Complex multidimensional array in C++ Pin
Vaclav_20-Jan-19 4:39
Vaclav_20-Jan-19 4:39 
GeneralRe: Complex multidimensional array in C++ Pin
Richard MacCutchan20-Jan-19 5:06
mveRichard MacCutchan20-Jan-19 5:06 
GeneralRe: Complex multidimensional array in C++ Pin
Vaclav_20-Jan-19 7:15
Vaclav_20-Jan-19 7:15 
GeneralRe: Complex multidimensional array in C++ Pin
k505420-Jan-19 8:47
mvek505420-Jan-19 8:47 
That's way too much typing. Consider:

C++
#include <iostream>
 #include <iomanip>
 #include <map>
 #include <vector>

using namespace std;

 #define DEBUG

int main()
{
    map<int,vector<int>> IL9341Command = {{ {0x0, {{ 1, 2, 3, 4 }} },
                                            {0x1, {{ 4, 6, 7, }} },
                                            {0x4, {{ 9, 10, 11, 12, 13, 14 }} },
                                            {0xff, {{ 44, 55, 66, 77 }} } }};

 #ifdef DEBUG
    for(auto iter : IL9341Command) {
        cout << "IL9341Comand [ 0x" << hex << iter.first << " ] =";
        for(auto cmd : iter.second)
            cout << " 0x" << hex << cmd;
        cout << endl;
    }

    int *data = IL9341Command[0xff].data(); // get access to raw vector data

    cout << "\nCommand[0xff] data :";
    for(size_t i = 0; i < IL9341Command[0xff].size(); i++)
        cout <<  " 0x" << data[i];
    cout << endl;

 #endif // DEBUG

    return 0;
}

You can access the command data directly if you know the key via IL941Command[key], without having to iterate through the array, and as shown above, access to the "raw data" can be gained by calling data() on the vector. If you have C++17 then you can simplify the for(auto iter ...) loop as follows
for(auto [key, data] : IL9341Command) {
        cout << "IL9341Comand [ 0x" << hex << key << " ] =";
        for(auto cmd : data)
            cout << " 0x" << hex << cmd;
        cout << endl;
    }


modified 20-Jan-19 15:07pm.

GeneralRe: Complex multidimensional array in C++ Pin
k505420-Jan-19 8:52
mvek505420-Jan-19 8:52 
GeneralRe: Complex multidimensional array in C++ Pin
Vaclav_21-Jan-19 6:56
Vaclav_21-Jan-19 6:56 
GeneralRe: Complex multidimensional array in C++ Pin
Richard MacCutchan21-Jan-19 22:36
mveRichard MacCutchan21-Jan-19 22:36 
AnswerRe: Complex multidimensional array in C++ Pin
k505420-Jan-19 4:54
mvek505420-Jan-19 4:54 
GeneralRe: Complex multidimensional array in C++ Pin
Vaclav_20-Jan-19 10:13
Vaclav_20-Jan-19 10:13 
AnswerRe: Complex multidimensional array in C++ Pin
Stefan_Lang20-Jan-19 21:29
Stefan_Lang20-Jan-19 21:29 
Questionis there any relation object states control and encapsulation? Pin
nig3D19-Jan-19 8:05
nig3D19-Jan-19 8:05 
AnswerRe: is there any relation object states control and encapsulation? Pin
phil.o19-Jan-19 9:41
professionalphil.o19-Jan-19 9:41 
AnswerRe: is there any relation object states control and encapsulation? Pin
CPallini19-Jan-19 10:34
mveCPallini19-Jan-19 10:34 
JokeRe: is there any relation object states control and encapsulation? Pin
Peter_in_278019-Jan-19 10:51
professionalPeter_in_278019-Jan-19 10:51 
GeneralRe: is there any relation object states control and encapsulation? Pin
nig3D20-Jan-19 4:23
nig3D20-Jan-19 4:23 
GeneralRe: is there any relation object states control and encapsulation? Pin
Peter_in_278020-Jan-19 10:49
professionalPeter_in_278020-Jan-19 10:49 
GeneralRe: is there any relation object states control and encapsulation? Pin
nig3D27-Jan-19 10:25
nig3D27-Jan-19 10:25 
AnswerRe: is there any relation object states control and encapsulation? Pin
leon de boer19-Jan-19 18:47
leon de boer19-Jan-19 18:47 
QuestionWhat are the programmers' opinions about Plain English Programming? Pin
Quantum Robin18-Jan-19 8:04
Quantum Robin18-Jan-19 8:04 
QuestionRe: What are the programmers' opinions about Plain English Programming? Pin
David Crow18-Jan-19 16:21
David Crow18-Jan-19 16:21 
AnswerRe: What are the programmers' opinions about Plain English Programming? Pin
leon de boer19-Jan-19 2:48
leon de boer19-Jan-19 2:48 
GeneralRe: What are the programmers' opinions about Plain English Programming? Pin
Stefan_Lang20-Jan-19 22:08
Stefan_Lang20-Jan-19 22:08 
AnswerRe: What are the programmers' opinions about Plain English Programming? Pin
Alan Balkany22-Jan-19 5:45
Alan Balkany22-Jan-19 5:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.