Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting from C++ ifstream to C# FileStream
    text
    copied!<p>I am attempting to learn SharpDX via DirectX tutorials. I have this line of code in the C++ project I am working from:</p> <pre><code>std::ifstream fin("Models/skull.txt"); if(!fin) { MessageBox(0, L"Models/skull.txt not found.", 0, 0); return; } UINT vcount = 0; UINT tcount = 0; std::string ignore; fin &gt;&gt; ignore &gt;&gt; vcount; fin &gt;&gt; ignore &gt;&gt; tcount; fin &gt;&gt; ignore &gt;&gt; ignore &gt;&gt; ignore &gt;&gt; ignore; float nx, ny, nz; XMFLOAT4 black(0.0f, 0.0f, 0.0f, 1.0f); std::vector&lt;Vertex&gt; vertices(vcount); for(UINT i = 0; i &lt; vcount; ++i) { fin &gt;&gt; vertices[i].Pos.x &gt;&gt; vertices[i].Pos.y &gt;&gt; vertices[i].Pos.z; vertices[i].Color = black; // Normal not used in this demo. fin &gt;&gt; nx &gt;&gt; ny &gt;&gt; nz; } fin &gt;&gt; ignore; fin &gt;&gt; ignore; fin &gt;&gt; ignore; mSkullIndexCount = 3*tcount; std::vector&lt;UINT&gt; indices(mSkullIndexCount); for(UINT i = 0; i &lt; tcount; ++i) { fin &gt;&gt; indices[i*3+0] &gt;&gt; indices[i*3+1] &gt;&gt; indices[i*3+2]; } fin.close(); </code></pre> <p>And I would like to know how to covert this over to C#. I am 99% sure I need to be using <code>System.IO.FileStream</code> but I am unsure how all the C++ stuff works. What is really messing me up is the <code>fin &gt;&gt; ignore &gt;&gt; vcount;</code> If someone can explain to me how to do the same thing in C# I can probably figure it out from there.</p> <p>As requested the text file resembles this:</p> <pre><code>VertexCount: 31076 TriangleCount: 60339 VertexList (pos, normal) { 0.592978 1.92413 -2.62486 0.572276 0.816877 0.0721907 0.571224 1.94331 -2.66948 0.572276 0.816877 0.0721907 0.609047 1.90942 -2.58578 0.572276 0.816877 0.0721907 … } TriangleList { 0 1 2 3 4 5 6 7 8 … } </code></pre>
 

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