I am trying to port some code which runs fine on Linux to Win32. I have checked the current working directory and the program IS working in the same dir as the file. For some reason, however, it cannot read it. This is the function that does the reading. I just pass “filename.txt” to it:
inline const GLchar* readTextFile(const char* filename) {
std::fstream shaderFile(filename,std::ios::in);
std::string shader;
std::stringstream buffer;
buffer << shaderFile.rdbuf();
shader = buffer.str();
return shader.c_str();
}
Any tips on troubleshooting this?
many thanks in advance.
You are returning a locally allocated string buffer, that get lost when the function exits.
Allocate the buffer statically inside or (better) return the string instead.