For some reason I am getting the following error with the following code. It does not really make sense to me that std::string in one case has a c_str function and in another dosen't.
../Shader.hpp:29:19: error: request for member ‘c_str’ in ‘code’, which is of non-class type ‘std::__cxx11::string(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> > (*)()) {aka std::__cxx11::basic_string<char>(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> > (*)())}’
loadString(code.c_str());
void loadFile(const char* fn)
{
std::ifstream fin(fn);
if(!fin.good())
throw std::runtime_error("File could not be opened.");
std::string code(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());
fin.close();
loadString(code.c_str());
}
Then just to check I added another string.
void loadFile(const char* fn)
{
std::ifstream fin(fn);
if(!fin.good())
throw std::runtime_error("File could not be opened.");
std::string code(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());
fin.close();
std::string test = "test";
loadString(test.c_str());
}
Now this code compiles. I don't get why it works for one version but not the other.