Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring text file into a class
    primarykey
    data
    text
    <p>I am currently trying to read in characters into a class that looks like this</p> <pre><code> struct data { string segment; string name; double length; double radius; double wall_thickness; double young_modulus; double compliance; }; </code></pre> <p>I also have a vector that contains the following elements:</p> <pre><code> 2A Aorta_Ascendens 2 1.47 .164 4 53.4 2B Aorta_Ascendens 2 1.44 .161 4 51.0 3A </code></pre> <p>I want to read in the text file into each part, and currently this is my algorithm to continuously read through the text file and add each part respectively.</p> <pre><code>int place = 0; while (place != temp_data.size()){ int counter = 0; for (counter; counter &lt;= 7; ++counter){ istringstream is(temp_data[place + counter]); if (counter == 0){ is &gt;&gt; a.segment; } if (counter == 1){ is &gt;&gt; a.name; } if (counter == 2){ is &gt;&gt; a.length; } if (counter == 3){ is &gt;&gt; a.radius; } if (counter == 4){ is &gt;&gt; a.wall_thickness; } if (counter == 5){ is &gt;&gt; a.young_modulus; } if (counter == 6){ is &gt;&gt; a.compliance; } } counter = counter - 1; //since the next segment is at temp_data[7], must subtract one to have place = 7. place = counter + place; v.push_back(a); } </code></pre> <p>The problem I ran into is trying to find a way to make sure the right part of the text goes into the right part of the object. for the first seven lines of text the object should be like this :</p> <pre><code>segment: 2A name: Aorta_Ascendens length: 2 radius: 1.47 wall_thickness: .164 young modulus: 4 compliance: 53.4 </code></pre> <p>This should repeat the same way for the whole of the text file. temp_data is a vector that holds the elements that need to be added into the object, but I cant find a good way to continually cycle through the vector and put the elements into the right place. </p> <p>The algorithm I made has a counter and a place holder, the counter would cycle through the vector points and the place holder would hold spot for the first object's data member, in this case segment. At the end of the algorithm, place should equal the size of temp_data and get out of the loop. But I am having a problem when it compiles and runs, it seems to be putting the wrong element into the wrong object member.</p> <p>Any ideas?</p>
    singulars
    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.
 

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