0

I've been getting this error: basic_ios::clear: iostream error. I don't know why this is occurring when I'm simply reading a file's buffer contents into streams and into strings. Why is it occurring?

            vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
            fShaderfile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
            try{
                vShaderFile.open(vertexpath);
                fShaderfile.open(fragmentpath);
                std::stringstream vShaderStream, fShaderStream;
                // read file's buffer contents into streams
                vShaderStream << vShaderFile.rdbuf();
                
                fShaderStream << fShaderfile.rdbuf();       
                // close file handlers
                vShaderFile.close();
                fShaderfile.close();
                // convert stream into string
                vertexCode   = vShaderStream.str();
                fragmentCode = fShaderStream.str(); 
                
            }catch(std::ifstream::failure& e){
                 std::cout << "Shader file read error: " << e.what() << std::endl;
            }

vShaderFile and fShaderfile are both std::ifstream's.

ChinDaMay
  • 204
  • 1
  • 11
  • First guess is that the paths are not what you expect. Perhaps try `if (!file.open(path)) cout << "failed to open " << path;` – BoP Jul 04 '22 at 19:34
  • Reaching the end of file, which is guaranteed by `vShaderStream << vShaderFile.rdbuf();` results in a `failbit`, and a thrown exception. See the linked question for more information. The End. – Sam Varshavchik Jul 04 '22 at 19:34
  • I don't think the dupe answers this. In the dupe, the asker reads past the end of the file. In this case, I'd expect `rdbuf()` to read up to the end without triggering fail and instead give the case described by templatetypedef at the end of the dupe. I think you're still got a problem somewhere else. – user4581301 Jul 04 '22 at 19:58

0 Answers0