Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the main problem is that your program isn't creating the <code>map</code> that you think it is, and that your program isn't displaying the vector items that you think it is.</p> <p>For the purposes of this answer, I'm assuming that the identifiers <code>ID1</code> and <code>ID2</code> are simple integer variables or macros that are simple integer constants (and have a value greater than 0, or the program will essentially do nothing). If <code>ID1</code> or <code>ID2</code> are something more complex, it's difficult to reason what the program should or might be doing without more information about what those identifiers are.</p> <p>Lets look closely at what's happening in each nested loop.</p> <p>In the first:</p> <pre><code>Maptest[ID1].push_back(ID2*0.01); </code></pre> <p>The <code>map</code> key being used is always the same since <code>ID1</code> isn't being changed. So <code>Maptest</code> only ever contains a single item, with a key value of <code>ID1</code> and a vector that gets elements added to it with each loop iteration. Also, each element that is added to the vector has the same value: <code>(ID2 * 0.01)</code>.</p> <p>In particular, note that even though the nested loops are controlled by the variables <code>i</code> and <code>j</code>, those variables don't get used in the <code>push_back()</code> call. So after that first nested loop completes, <code>Maptest</code> contains a single mapping, which has a key of <code>ID1</code> and a vector with <code>(ID1 * ID2)</code> elements in it. Each element of that vector has a value of <code>(ID2 * 0.01)</code>.</p> <p>In the second nested loop, you're always finding the same item in <code>Maptest</code> - the one with the key <code>ID1</code> (which happens to be the only item in the <code>map</code>). The <code>vector&lt;double&gt;</code> part of that mapping has an array with <code>(ID1 * ID2)</code> elements, each of which has the same value. The loop them formats the element at index <code>ID2</code> into <code>testString</code>. Always the same element from the same vector. Not that it really matters which element is formatted into the string, since each vector element has the same value.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload