Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It <em>sounds</em> like your <code>time</code> string may have a carriage return <code>\r</code> in it. If that's the case, then outputting using your first method will <em>still</em> output the count and separator, but the <code>\r</code> will return to the start of the line and begin overwriting it.</p> <p>Your second method will not overwrite the count since it's on the previous line (a <code>\r</code> will have little visible effect if you're already at the start of the line).</p> <p>If you're running on a UNIX-like platform, you can pipe the output through something like <code>od -xcb</code> (a hex dump filter) to see if there is a <code>\r</code> in the output.</p> <p>Alternatively, if you have a string in your code, you can see if it contains a carriage return with something like:</p> <pre><code>std::string s = "whatever"; size_t pos = s.find ('\r'); if (pos != std::string::npos) { // carriage return was found. } </code></pre> <p>By way of example, the following program:</p> <pre><code>#include &lt;iostream&gt; int main (void) { std::string s1 = "strA"; std::string s2 = "\rstrB"; std::string s3 = "strC"; std::cout &lt;&lt; s1 &lt;&lt; '|' &lt;&lt; s2 &lt;&lt; '|' &lt;&lt; s3 &lt;&lt; '\n'; std::cout &lt;&lt; "=====\n"; std::cout &lt;&lt; s1 &lt;&lt; '|' &lt;&lt; '\n'; std::cout &lt;&lt; s2 &lt;&lt; '|' &lt;&lt; s3 &lt;&lt; '\n'; std::cout &lt;&lt; "=====\n"; size_t pos = s2.find ('\r'); if (pos != std::string::npos) std::cout &lt;&lt; "CR found at " &lt;&lt; pos &lt;&lt; '\n'; return 0; } </code></pre> <p>seems to output the following:</p> <pre><code>strB|strC ===== strA| strB|strC ===== CR found at 0 </code></pre> <p>but in fact that first line is actually:</p> <pre><code>strA|(\r)strB|strC </code></pre> <p>where <code>(\r)</code> is the carriage return.</p> <hr> <p>And keep in mind you rarely need <code>endl</code> - it's effectively a <code>\n</code> with a flush which is not really necessary in most cases. You can just get away with using <code>\n</code> and let the automated flushing take care of itself.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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