Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to store the data produced during a while loop?
    primarykey
    data
    text
    <p>I started C++ (as the 1st programming language I ever tried to learn) a few hours ago, and I am blocked on a very simple (I am sure of that) problem...</p> <p>Basically I wanted to start with an algorithm that would give me, on a 2D surface of given height and width of integer values, a local "density value" for any point (defined by integers a &amp; b).</p> <p>The problem I have is, since I want to reuse the result, how to store the data that shows up when the program is started (the data that appears because of the command:</p> <pre><code>//print cout&lt;&lt;D&lt;&lt;endl; </code></pre> <p>I really tried hard to find a solution without finding anything... It could be stored in an external file, or in a kind of "buffer", any good solution would do the thing.</p> <p>I just have to keep this data-list</p> <p>Thanks!</p> <p>here's my code :</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; //#include &lt;vector&gt; (the solution??) #include &lt;cstdlib&gt; #include &lt;string&gt; #include &lt;sstream&gt; using namespace std; // constant values float Da=0.1; //densities float Db=0.5; float Dc=1; double Dd=1/3; int l = 99; //width &amp; height int h = 99; float u = 1; // UNIT int main () { float a = 0; float b = 0; // Local variables while (a&lt;l+1, b&lt;h+1){ //values for given a &amp; b double DL = Da-Da*(b/h)+Dc*(b/h); double DR = Db-Db*(b/h)+Dd*(b/h); double D = DL-DL*(a/l)+DR*(a/l); //print cout&lt;&lt;D&lt;&lt;endl; // next pixel &amp; next line a++; if (a&gt;l) { a = 0; b = b+u; } } } </code></pre>
    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.
 

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