C++ set container can't erase odd numbers This program asks the user for a number, then stores all numbers up to and including it into a set container. The problem is that I to erase specific numbers, but I can't because the program freezes whenever I try to erase an odd number (signified by NUMBER below). It works fine when I erase even numbers though. However, I noticed that if I change the initial value of y to an even number, I become unable to erase even numbers. Here I have it set to an odd number. What did I do wrong?  #include &lt;iostream&gt; #include &lt;set&gt; using namespace std;  int main() { set&lt;int&gt;s; set&lt;int&gt;::iterator cnt; int n,x,y=1; cout&lt;&lt;"Number: "; cin&gt;&gt;n; for(x=0;x&lt;n-1;x++) {     s.insert(y);     y++; } for(cnt=s.begin();cnt!=s.end();cnt++) {     if(*cnt==NUMBER)     s.erase(cnt); } for(cnt=s.begin();cnt!=s.end();cnt++) cout&lt;&lt;*cnt&lt;&lt;"\n"; return 0; }
What happens if you call erase() on a map element while iterating from begin to end? In the following code I loop through a map and test if an element needs to be erased.  Is it safe to erase the element and keep iterating or do I need to collect the keys in another container and do a second loop to call the erase()?  map&lt;string, SerialdMsg::SerialFunction_t&gt;::iterator pm_it; for (pm_it = port_map.begin(); pm_it != port_map.end(); pm_it++) {     if (pm_it-&gt;second == delete_this_id) {         port_map.erase(pm_it-&gt;first);     } }   UPDATE: Of course, I then  which I didn't think would be related but answers my question.
What is the difference between can and could in 'Can/could you please explain this to me?' How many authors should attend a conference? I wrote a paper with  3 other students regarding my final year project in mechanical engineering. It was recently selected for a conference in NIT Delhi. Minimum one author is required to present and the price is pretty steep for the participation certificate.Should all of us attend the conference or just one of us? Does the certificate hold any value? Check if partition is encrypted "Welcome to emergency mode!" Think it is a fsck problem My computer booted to a black screen with this error message.  Welcome to emergency mode! After logging in,type "journalctl -xb" to view    system logs, "systemctl reboot" to reboot, "systemctl default" or ^D to    try again to boot into default mode.   journalctl -xb snippet (what I think is wrong):  -- Unit systemd-fsckd.service has begun starting up. juli 09 15:40:16 kim-SSD-Sationary systemd-fsck[414]: /dev/sdb1 contains a file system with errors, check forced. juli 09 15:40:16 kim-SSD-Sationary systemd-fsck[414]: /dev/sdb1: Inodes that were part of a corrupted orphan linked list found. juli 09 15:40:16 kim-SSD-Sationary systemd-fsck[414]: /dev/sdb1: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY. juli 09 15:40:16 kim-SSD-Sationary systemd-fsck[414]: (i.e., without -a or -p options) juli 09 15:40:16 kim-SSD-Sationary systemd-fsck[414]: fsck failed with error code 4. juli 09 15:40:16 kim-SSD-Sationary systemd-fsck[414]: Running request emergency.target/start/replace juli 09 15:40:16 kim-SSD-Sationary systemd[1]: systemd-fsck-root.service: main process exited, code=exited, status=1/FAILURE juli 09 15:40:16 kim-SSD-Sationary systemd[1]: Failed to start File System Check on Root Device. -- Subject: Unit systemd-fsck-root.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --  -- Unit systemd-fsck-root.service has failed. --  -- The result is failed. juli 09 15:40:16 kim-SSD-Sationary systemd[1]: Unit systemd-fsck-root.service entered failed state. juli 09 15:40:16 kim-SSD-Sationary systemd[1]: systemd-fsck-root.service failed. juli 09 15:40:16 kim-SSD-Sationary systemd[1]: Starting Remount Root and Kernel File Systems... -- Subject: Unit systemd-remount-fs.service has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel   I ignored other errors like: ACPI PCC probe failed, nvidia not proprietary, etc.  I can access my PC by pressing Ctrl+D , but it is annoying. If a PIC MCU provides multiple Vdd/Vss should you provide power to them all? Take a look at this example schematic:  The chip in question is the  and as you can see power is provided on both sides (with a 100nF cap to smooth noise I guess). Is this strictly required or could you put power into one side and just ignore the other? I know that I have just put power in one side and everything still seems to work fine but I feel uneasy with doing that. I feel that they would not waste pins that could be doing something useful by having an extra pair of power in/out pins. For what purpose does this PIC MCU (and others like it) have multiple power pins? Indentation shortcuts in Visual Studio How to get a combined ticket in IRCTC (Indian Railway) Suppose I want to go from Station A to Station C but Station C is not a stoppage of some train say train 01, so I can get a combined ticket from station A to Station B  through train 01 plus Station B to station C through a different train say 02, so my total fare will be of same ticket as from Station A to Station C.  We can get Combined ticket from the Booking Window but how's that possible on the IRCTC website? How to download packages from a command-line given repository? What software can I use to write on PDFs? I'm used to OS X where the system PDF viewer will let you draw and write text on top of any PDF document. You can then flatten it and save as a new PDF. It saves paper and time so you can fill in any form without printing it and scanning it back to the computer.  It also lets you insert a scanned image of your signature.  Is there software for Ubuntu that would do that? In my grammar book (English Grammar, HarperCollins Publishers), I read that none is occasionally treated as plural, but it is usually regarded as singular. Can you give me an example of sentence where none is used as plural pronoun? To convert an MKV to AVI, I do two things. The first thing I do is this:  ffmpeg -i filename.mkv -vcodec copy -acodec copy output.avi   or this:  ffmpeg -i filename.mkv -sameq -acodec copy output.avi   Either of these will convert the MKV to an AVI, but the problem is that the video does not play smoothly for some reason. That's fine though, because if I do one more thing it gets fixed:  ffmpeg -i output.avi -vcodec mpeg4 -b 4000k -acodec mp2 -ab 320k converted.avi   After I do this then the file plays without problem. I had success doing it this way for one file, but then I tried it on another file, and there is a slight, but noticeable loss in video quality. This is the output I get when doing the second step:  FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers   built on Dec 29 2010 18:02:10 with gcc 4.2.1 (Apple Inc. build 5664)   configuration:    libavutil     50.15. 1 / 50.15. 1   libavcodec    52.72. 2 / 52.72. 2   libavformat   52.64. 2 / 52.64. 2   libavdevice   52. 2. 0 / 52. 2. 0   libswscale     0.11. 0 /  0.11. 0  Seems stream 0 codec frame rate differs from container frame rate: 359.00 (359/1) -&gt; 29.92 (359/12) Input #0, avi, from 'output.avi':   Metadata:     ISFT            : Lavf52.64.2   Duration: 00:04:17.21, start: 0.000000, bitrate: 3074 kb/s     Stream #0.0: Video: mpeg4, yuv420p, 704x480 [PAR 229:189 DAR 5038:2835], 29.92 fps, 29.92 tbr, 29.92 tbn, 359 tbc     Stream #0.1: Audio: vorbis, 48000 Hz, stereo, s16 Output #0, avi, to 'converted.avi':   Metadata:     ISFT            : Lavf52.64.2     Stream #0.0: Video: mpeg4, yuv420p, 704x480 [PAR 229:189 DAR 5038:2835], q=2-31, 4000 kb/s, 29.92 tbn, 29.92 tbc     Stream #0.1: Audio: mp2, 48000 Hz, stereo, s16, 320 kb/s Stream mapping:   Stream #0.0 -&gt; #0.0   Stream #0.1 -&gt; #0.1   I just used arbitrarily large settings on the second step and it worked nicely before but not in this case. What settings should I use? Hint on how to prove the identity $\sum_{0 \leq k \leq n } \binom{k}{m} = \binom{n + 1}{m + 1}$ I am just curious, I use handlebar mounted lights, and since I have multiple bikes to switch, it's a lot of trouble changing the light from one to another. So, I am thinking of switching to helmet mounted lights.  Give me your point of view. Why or why not? Which is better suitable for which riding type? A net $\varphi : [0, \omega_1) \to M$ on a metric space $M$ converges $\iff \varphi$ is eventually constant I want to prove that      If $M$ is a metric space, then a net $\varphi : [0, \omega_1) \to M$ converges if and only if $\varphi$ is eventually constant. ($[0, \omega_1)$ is the set of ordinals less than $\omega_1$, where $\omega_1$ is the first uncountable ordinal, with the order topology).   $(\Leftarrow)$ is clear.  My trouble is with $(\Rightarrow)$. Suppose that $\varphi \rightarrow x$.  Let $U = \{ \alpha \in [0, \omega_1) \, \mid \varphi(\alpha) \neq x \}.$  If $U = \emptyset $ we are done, so assume $U \neq \emptyset$. Since $[0, \omega_1)$ is well ordered, there is a $\alpha_1 \in U$ such that $ \alpha_1 \leq \alpha \, \, \forall \alpha \in U.$  If $ U \setminus \alpha_1 = \emptyset$ we are done. If not, we repeat the procedure.  It is clear that if $card(U) = n$ for some $n \in \omega$ then we only have a finite set of ordinals $\{\alpha_1, \ldots, \alpha_n\}=U$ so $\varphi$ is constant for $\alpha &gt; \alpha_n.$  If $U$ is countably infinite, then $U = \{\alpha_n\}_{n \in \omega}$ and since $[0, \omega_1)$ is sequentially compact and the $\alpha_n$'s are countable ordinals  we obtain a convergent subsequence $\{\alpha_{n_k}\}$ of $U$ to some countable ordinal $\beta \in [0, \omega_1)$ $[\beta = \cup_{n_k \in \omega}\alpha_{n_k}???],$ hence $\varphi$ is constant for all $ \alpha &gt; \beta.$     But what if $U$ is uncountable?    Idea: If $U = [0, \omega_1),$ then since $\varphi \rightarrow x$, for every $n \in \omega$ there is $\alpha_n \in U$ such that $\alpha \geq \alpha_n \implies \varphi(\alpha) \in B_{\frac{1}{n}}(x).$ This is a countable sequence, so since $[0, \omega_1)$ is sequentially compact, there is a subsequence converging to a countable ordinal $\beta \in [0, \omega_1)$. Clearly, $\beta$ satisfies that $\phi(\beta) \in B_{\frac{1}{n}}$(x) for every $n \in \omega.$     We can conclude that $\varphi(\beta)= x$ right?   For if $\varphi(\beta) \neq x$, then taking $n$ such that $0 &lt; \frac{1}{n} &lt; d(x, \varphi(\beta)),$ we would have that $\varphi(\beta) \not \in B_{\frac{1}{n}}(x),$ contradicting the hypothesis.  I feel pretty confident about this, but If someone sees an error in the argument, please comment. Thanks. Atiyah-Macdonald, Exercise 8.3: Artinian iff finite k-algebra. Atiyah Macdonald, Exercise 8.3. Let $k$ be a field and $A$ a finitely generated $k$-algebra. Prove that the following are equivalent:   (1) $A$ is Artinian.   (2) $A$ is a finite $k$-algebra.   I have a question in the proof of (1$\Rightarrow$2): By using the structure theorem, we may assume that $(A,m)$ is an Artin local ring. Then $A/m$ is a finite algebraic extension of $k$ by . Since $A$ is Artinian, $m$ is the nilradical of $A$ and thus $m^n=0$ for some $n$. Thus we have a chain $A \supseteq m \supseteq m^2 \supseteq \cdots \supseteq m^n=0$. Since $A$ is Noetherian, $m$ is finitely generated and hence each $m^i/m^{i+1}$ is a finite dimensional $A/m$-vector space, hence a finite dimensional $k$-vector space.  But now how can I deduce that $A$ is a finite dimensional $k$-vector space? How can I do a line break (line continuation)? Pre-image of a measurable set A is always measurable? I am trying to run the following model:         I(week^2):mutation_status +         (week + I(week^2) | subject_id) ,          data = sim_dat)  This is the output I get from this model. The correlation between week and I(week)^2 is rather high (-0.95) and I was curious to know how I can change my data simulation code to lower that value. I am also having issues with convergence and would love to get thoughts on how to avoid issues regarding convergence. Thank you! Linear mixed model fit by REML. t-tests use Satterthwaite's method [lmerModLmerTest]  Formula: fetal_weight ~ week + mutation_status + week:mutation_status + I(week^2) +  I(week^2):mutation_status + (week + I(week^2) | subject_id) Data: sim_dat  REML criterion at convergence: 114  Scaled residuals:      Min      1Q  Median      3Q     Max  -1.9343 -0.3980 -0.0075  0.4168  1.9928   Random effects:  Groups     Name        Variance  Std.Dev. Corr         subject_id (Intercept)   1.51524  1.2309                          week         61.01832  7.8114   0.16                   I(week^2)   496.20236 22.2756  -0.19 -0.95  Residual                 0.05892  0.2427              Number of obs: 100, groups:  subject_id, 20  Fixed effects:                            Estimate Std. Error       df t value       Pr(&gt;|t|)     (Intercept)                  3.1331     0.4226  17.9961   7.413 0.000000713699 *** week                        -1.2465     3.5210  18.0053  -0.354          0.727     mutation_statusY             0.5061     0.5977  17.9961   0.847          0.408     I(week^2)                   34.5706    10.8146  18.0084   3.197          0.005 **  week:mutation_statusY       -1.0697     4.9795  18.0053  -0.215          0.832     mutation_statusY:I(week^2) 202.5521    15.2942  18.0084  13.244 0.000000000101 *** --- Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1  Correlation of Fixed Effects:             (Intr) week   mttn_Y I(w^2) wk:m_Y week        -0.160                             muttn_sttsY -0.707  0.113                      I(week^2)    0.145 -0.966 -0.103               wk:mttn_stY  0.113 -0.707 -0.160  0.683        mtt_Y:I(^2) -0.103  0.683  0.145 -0.707 -0.966  Code for data simulation: set.seed(123)  # set the seed J &lt;- 20  # number of individuals (clusters) cs &lt;- 5  # number of time points (cluster size) gam &lt;- c(0, 0.75, 1.34)  # fixed effects G &lt;- matrix(c(1.75, 0, 0,               0, 0.0125, 0,               0,0,0.0625),              nrow = 3)  # random effect variances (G-matrix) sigma2 &lt;- 0.08  mutation_status &lt;- rep(0:1, each = 5) mutation_status &lt;- rep(mutation_status, times = 10)  X &lt;- cbind(1, seq_len(cs),             (seq_len(cs))^2)  # for each individual X &lt;- X[rep(seq_len(cs), J), ]  X &lt;- X[rep(seq_len(cs), J), ]  X[,2] &lt;- X[,2]*0.05 X[,3] &lt;- X[,3]*0.05  # repeat each row cs times pid &lt;- seq_len(J)  # individual id pid &lt;- rep(pid, each = cs)   # Generate person-level (lv-2) random effects uj &lt;- lmf::rmnorm(J, mean = rep(0, 2), varcov = G)  # Generate repeated-measure-level (lv-1) error term eij &lt;- rnorm(J * cs, sd = sqrt(sigma2))  # Compute beta_j's betaj &lt;- matrix(gam, nrow = J, ncol = 3, byrow = TRUE) + uj  # Compute outcome: y &lt;- rowSums(X * betaj[pid, ]) + eij + mutation_status*X[ , 3]*10 + 3  # Form a data frame sim_dat &lt;- tibble(y, time = X[ , 2], pid, mutation_status) sim_dat &lt;- sim_dat[,c(3,2,4,1)] colnames(sim_dat) &lt;- c(&quot;subject_id&quot;, &quot;week&quot;, &quot;mutation_status&quot;, &quot;fetal_weight&quot;) sim_dat$week_2 &lt;-sim_dat$week*5 + 15  sim_dat$mutation_status &lt;- as.factor(ifelse(sim_dat$mutation_status == 0, &quot;N&quot;, &quot;Y&quot;)) sim_dat$subject_id &lt;- as.factor(sim_dat$subject_id ) #Model Building What are the advantages and disadvantages of using the GAC? And on top of that, are there cases where one has to use the global assembly cache or where one cannot use it? Combining two sorted lists in Python I have two lists of objects. Each list is already sorted by a property of the object that is of the datetime type. I would like to combine the two lists into one sorted list. Is the best way just to do a sort or is there a smarter way to do this in Python?