title: Compiling OpenGL shaders causes syntax errors
body: <p>I have two simple shaders (vertex and fragment)</p>
  
  <h1>Vertex Shader</h1>
  
  <pre><code>#version 330 core
  
  //=============================================
  //---[Structs/Vertex Data]---------------------
  //=============================================
  
  layout(location = 0) in vec3 vertexPosition_modelspace;
  
  //=============================================
  //---[Variables]-------------------------------
  //=============================================
  
  uniform mat4 projection;
  uniform mat4 view;
  
  //=============================================
  //---[Vertex Shader]---------------------------
  //=============================================
  
  void main()
  {
     gl_Position = projection * view * vertexPosition_modelspace;
  }
  </code></pre>
  
  <h1>Fragment Shader</h1>
  
  <pre><code>#version 330 core
  
  //=============================================
  //---[Output Struct]---------------------------
  //=============================================
  
  out vec3 colour;
  
  //=============================================
  //---[Fragment Shader]-------------------------
  //=============================================
  
  void main()
  {
      colour = vec3(1, 0, 0);
  }
  </code></pre>
  
  <p>I am trying to compile them and I get the following error</p>
  
  <p><em>error C0000: syntax error, unexpected $undefined, expecting "::" at token "undefined"</em></p>
  
  <p>I believe this may have something to do with the way I am reading the files.  Here is an example for the vertex shader file</p>
  
  <pre><code>std::string VertexShaderCode = FindFileOrThrow(vertex_file_path);
  std::ifstream vShaderFile(VertexShaderCode.c_str());
  std::stringstream vShaderData;
  vShaderData &lt;&lt; vShaderFile.rdbuf();
  vShaderFile.close();
  </code></pre>
  
  <p>The file is then compiled using</p>
  
  <pre><code>char const *VertexSourcePointer = VertexShaderCode.c_str();
  glShaderSource(VertexShaderID, 1, &amp;VertexSourcePointer , NULL);
  glCompileShader(VertexShaderID);
  </code></pre>
  
  <p>How can I efficiently read in the files and avoid these errors?</p>
  
  <p>EDIT:</p>
  
  <p>Correct compile:</p>
  
  <pre><code>const std::string &amp;shaderText = vShaderData.str();
  GLint textLength = (GLint)shaderText.size();
  const GLchar *pText = static_cast&lt;const GLchar *&gt;(shaderText.c_str());
  glShaderSource(VertexShaderID, 1, &amp;pText, &amp;textLength);
  glCompileShader(VertexShaderID);
  </code></pre>