I'm trying to load text from a file into a const char*
instance. I came across this answer and adapted it as:
std::ifstream vertex_shader_stream("shaders/demo1_vert.glsl");
std::string vertex_shader_string(
(std::istreambuf_iterator<char>(vertex_shader_stream)),
std::istreambuf_iterator<char>());
const char *vertex_shader_bytes = vertex_shader_string.c_str();
What I'm having trouble understanding is why the first argument to std::string
is wrapped in parens ()
as (std::istreambuf_iterator<char>(vertex_shader_stream))
. I thought this might have been some redundant typing, but it appears to fail without them when calling c_str
error: request for member ‘c_str’ in ‘vertex_shader_string’, which is of non-class type ‘std::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> > (*)())’}
[build] 61 | const char *vertex_shader_text = vertex_shader_string.c_str();
[build] | ^~~~~
I'm not groking the error here, can someone explain this to me in detail what's going on? I'm sure this is probably a duplicate, so feel free to close vote if that's the case, I just don't know the right terms to search for!
Thanks!