Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ indexing values from a .txt file and reorder them in a new file with a different structure
    primarykey
    data
    text
    <p>I'm still a c++ beginner, I didn't by myself find a solution to the problems below.</p> <p>I have two problems:</p> <ul> <li><p>I want to load and index some values from a file <code>input.txt</code> structured as follows:</p> <blockquote> <p>(x) (y) [COLORNAME1, COLORNAME2, COLORNAME3, COLORNAME4] [density1, density2, density3, density4]</p> </blockquote> <ul> <li>I could create 10 <code>vector</code> containers, but I don't know how to "explain" to the program how to find the position of my data into the structure of the file...</li> </ul></li> </ul> <p><em>Example:</em> </p> <p>(notice that the same <code>'COLORNAME'</code>, for example: <code>'PINK'</code>, can appear at <code>colorname3</code> or <code>colorname2</code>, or anywhere in the 4 <code>colorname</code> positions)</p> <p>This is the data structure of the <code>input.txt</code> file:</p> <blockquote> <pre><code>1 23 ['PINKwA', 'GB', 'PINK', 'TUwA'][ 0.20078624 0.72376615 0.06735505 0.00809256] 1 24 ['PINKwA', 'GB', 'PINK', 'TUwA'][ 0.19900636 0.72874652 0.06998165 0.00226546] 1 25 ['OR0A', 'PINK', 'PINKwA', 'GB'][ 0.00155317 0.07161603 0.19596207 0.73086873] 1 26 ['OR0A', 'PINK', 'PINKwA', 'GB'][ 0.00409427 0.07261927 0.19211352 0.73117294] 1 27 ['OR0A', 'PINK', 'PINKwA', 'GB'][ 0.00663538 0.07362251 0.18826497 0.73147715] </code></pre> </blockquote> <p>My second problem is about reordering the imported data:</p> <ul> <li>I have a list of all <code>(x)</code> <code>(y)</code> and <code>COLORNAME</code></li> </ul> <p>I want to access: </p> <ul> <li>for any existing <code>(x)</code> <code>(y)</code> duet and,</li> <li>for a given <code>COLORNAME</code> </li> </ul> <blockquote> <p>COLORNAME (x) (y) (density) </p> </blockquote> <p>How can I do that? Thank you very much</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. COfor vectors indexing, since you have 10 vectors the values are indexed by the order you add them in. for example, if the first line was entered to the 10 vectors (each vector takes one column) all the data in the raw is indexed as 0. To access them, you simply access them as if they are arrays... like this: v[i] ................................................................... I didn't understand your second question
      singulars
    2. COMy second question: once everything's stored into vectors, I want to get for each triplet `(x)` `(y)` `COLORNAME` the associated `density`. In the file `input.txt` `COLORNAME1` is associated with `density1`, `COLORNAME2` with `density2`, and so on... I want a solution for an easy access to these data. Thanks
      singulars
    3. COyou want to access them and do what? read? write? since all 10 vectors have same indexing, you can make functions to deal with all 10 vectors while you type it only once... for eaxmple: void coutAll(int i){ cout << v2[i] << endl; cout << v3[i] << endl; cout << v4[i] << endl; cout << v5[i] << endl; cout << v6[i] << endl; cout << v7[i] << endl; cout << v8[i] << endl; cout << v9[i] << endl; cout << v10[i] << endl;}
      singulars
 

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