Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might not want to use <a href="http://www.cplusplus.com/reference/iostream/manipulators/endl/" rel="nofollow">std::endl</a>, because it flushes the output stream.</p> <p>Additionaly, if you want compatibility to Windows (and probably any other OS from Microsoft), you have to open the file in binary mode. Microsoft opens files in text mode by default, which usually has an incompatibility-feature (ancient-DOS-backward-compatibility) no one wants anymore: It replaces every "\n" with "\r\n".</p> <p>The PGM file format header is:</p> <pre><code>"P5" + at least one whitespace (\n, \r, \t, space) width (ascii decimal) + at least one whitespace (\n, \r, \t, space) height (ascii decimal) + at least one whitespace (\n, \r, \t, space) max gray value (ascii decimal) + EXACTLY ONE whitespace (\n, \r, \t, space) </code></pre> <p>This is an example to output a pgm to file:</p> <pre><code>#include &lt;fstream&gt; const unsigned char* bitmap[MAXHEIGHT] = …;// pointers to each pixel row { std::ofstream f("test.pgm",std::ios_base::out |std::ios_base::binary |std::ios_base::trunc ); int maxColorValue = 255; f &lt;&lt; "P5\n" &lt;&lt; width &lt;&lt; " " &lt;&lt; height &lt;&lt; "\n" &lt;&lt; maxColorValue &lt;&lt; "\n"; // std::endl == "\n" + std::flush // we do not want std::flush here. for(int i=0;i&lt;height;++i) f.write( reinterpret_cast&lt;const char*&gt;(bitmap[i]), width ); if(wannaFlush) f &lt;&lt; std::flush; } // block scope closes file, which flushes anyway. </code></pre>
    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.
    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