Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ remove & replace in a vector
    primarykey
    data
    text
    <p>I have a vector of vector like this:</p> <p>a: 0 1 0</p> <p>b: 1 0 1</p> <p>c: 0 1 1</p> <p>This part of my programm works. After I want to delete the 0 so I use remove_if and I want to replace the 1 by t and the position so I use replace_if for finally have something like</p> <p>a: t2</p> <p>b: t1, t3</p> <p>c: t2, t3</p> <p>These 2 things doesn't work on my program and I don't have idea anymore. I think one of the problem is that I want to have the "t" in a int but I don't know if I can use a string for this or not.</p> <p>Here is my code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;iterator&gt; int main (){ srand(time(0)); int e = (rand() % 10) + 3; int tim = (rand() % 10) +1 ; std::vector&lt; std::vector&lt;int&gt; &gt; myvector; std::cout &lt;&lt; "Time: 0 = Not available, 1 = available" &lt;&lt; std::endl; for(int vec = 0; vec &lt; e; vec++){ std::vector&lt;int&gt; newVector(tim); for(int i = 0; i &lt; tim; i++){ newVector[i] = (rand() % 2); } myvector.push_back(newVector); std::cout &lt;&lt; "The Time " &lt;&lt; (vec+1) &lt;&lt; " is "; for(int b = 0; b &lt; tim; b++){ int value = myvector[vec][b]; std::cout &lt;&lt; " " &lt;&lt; value &lt;&lt; " "; } } //Delete the 0 in time int int_to_remove = 0; remove_if(myvector.begin(), myvector.end(), int_to_remove); std::cout &lt;&lt; "The new Time "&lt;&lt; std::endl; copy(myvector.begin(), myvector.end(), output); //Change the name of 1 to t1 int int_to_replace = 1; replace_if(myvector.begin(), myvector.end(), int_to_replace, t(tim)); std::cout &lt;&lt; "The new Time"&lt;&lt; std::endl; copy(myvector.begin(), myvector.end(), output); return 0; } </code></pre> <p>Thanks</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.
 

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