Boost C++ Libraries: Ticket #9297: "boost::iostreams::file_descriptor_sink" doesn't support translation of line endings on Windows https://svn.boost.org/trac10/ticket/9297 <p> When a Windows file descriptor is opened in text mode, all newline characters written to this file are translated to CRLF. However, if <em>boost::iostreams::file_descriptor_sink</em> is used on such a file descriptor to write newlines to a stream, these newline characters are not translated to CRLF. </p> <p> The following sample program demonstrates this: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;boost/iostreams/device/file_descriptor.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/iostreams/stream.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;fcntl.h&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;io.h&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;string&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;sys/stat.h&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="k">static</span> <span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">str1</span> <span class="o">=</span> <span class="s">&quot;This is a line&quot;</span><span class="p">;</span> <span class="k">static</span> <span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">str2</span> <span class="o">=</span> <span class="s">&quot;This is another line&quot;</span><span class="p">;</span> <span class="kt">int</span> <span class="n">fd</span> <span class="o">=</span> <span class="n">_open</span><span class="p">(</span><span class="s">&quot;output.txt&quot;</span><span class="p">,</span> <span class="n">_O_WRONLY</span> <span class="o">|</span> <span class="n">_O_CREAT</span> <span class="o">|</span> <span class="n">_O_TRUNC</span> <span class="o">|</span> <span class="n">_O_TEXT</span><span class="p">,</span> <span class="n">_S_IREAD</span> <span class="o">|</span> <span class="n">_S_IWRITE</span><span class="p">);</span> <span class="n">_write</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span> <span class="n">str1</span><span class="p">.</span><span class="n">data</span><span class="p">(),</span> <span class="n">str1</span><span class="p">.</span><span class="n">size</span><span class="p">());</span> <span class="n">_write</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span> <span class="c1">// This writes &quot;\r\n&quot;</span> <span class="n">boost</span><span class="o">::</span><span class="n">iostreams</span><span class="o">::</span><span class="n">file_descriptor_sink</span> <span class="n">sink</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">iostreams</span><span class="o">::</span><span class="n">close_handle</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">iostreams</span><span class="o">::</span><span class="n">stream</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">iostreams</span><span class="o">::</span><span class="n">file_descriptor_sink</span><span class="o">&gt;</span> <span class="n">stream</span><span class="p">(</span><span class="n">sink</span><span class="p">);</span> <span class="n">stream</span> <span class="o">&lt;&lt;</span> <span class="n">str2</span><span class="p">;</span> <span class="n">stream</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="c1">// This only writes &quot;\n&quot;</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9297 Trac 1.4.3