How to Get Value of an element in a map Using Row and Column in C++? -


I want to know how to get a value from a map, in which there are two vectors using row and column strings For example, if the user enters "R1" and "C1" then the string "1" gets printed. In this code, I am using the array subscript to access the vector.

Sorry if this is a repeated question.

Thank you.

  #include & lt; String & gt; # Include & lt; Iostream & gt; #include & lt; Vector & gt; # Include & lt; Map & gt; using namespace std; Typedef Pair & lt; String, string & gt; pair; Typedef Map & lt; Pairs, string & gt; Map; Typingf vector & lt; String & gt; StrVec; Int main () {const int COL_SIZE = 3; Const int ROW_SIZE = 3; String line_arrow [ROW_SIZE] = {"R1", "R2", "R3"}; String col_array [COL_SIZE] = {"C1", "C2", "C3"}; StrVec column; StrVec line; {Row.push_back (col_array [i]) for (size_t i = 0; i & lt; COL_SIZE; ++ i); Column.push_back (row_array [i]); } Map map; Map :: Iterator Itater; String number [] = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}; Int number index = 0; For (int i = 0; i & lt; ROW_SIZE; ++ i) {for (int j = 0; j & lt; COL_SIZE; ++ j) {MyMap [make_pair (line [i], column [j] )] = Number [numberIndex]; Cout & lt; & Lt; Maimap [make-peer (line [ii], column [j]]]; ++ numberIndex; } Cout & lt; & Lt; Endl; } String User Inphpro; Cout & lt; & Lt; "Enter a line:" & lt; & Lt; Endl; Cin & gt; & Gt; UserInputRow; String user incol; Cout & lt; & Lt; "Enter a column:" & lt; & Lt; Endl; Cin & gt; & Gt; UserInputCol;   

}

You are not holding the map two vectors, This is the mapping of string from one pair to another string. I wonder what are your use cases to use such a structure instead of vectors?

You already have access to one element of the map in your code:

  cout < & Lt; Maimap [make-peer (line [ii], column [j]]];   

Note that the operator will be included in the map if the entry is not present, then it is not always intended.

You can repeat on a map the way in which each container is, and its key is sorted on:

 for  (console auto and P: mam map) {std :: cout & lt; & Lt; P.second & lt; & Lt; Std :: endl; }    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -