I'm using OpenGL and I need the contents of VertexShader.glsl to be put into a std::string
I've looked at the related StackOverflow posts about this but I don't really know how to match together data types and stuff to make it work.
Take for example this from Read file-contents into a string in C++
#include <fstream>
#include <string>
int main(int argc, char** argv)
{
std::ifstream ifs("myfile.txt");
std::string content( (std::istreambuf_iterator<char>(ifs) ),
(std::istreambuf_iterator<char>() ) );
return 0;
}
I have no clue what's happening after
std:: string content
Every time I have used std::string before has been like
std::string name = "2bdkid";
It's constructor #6 here:
template< class InputIt >
basic_string( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
Which does:
Constructs the string with the contents of the range
[first, last)
.
istreambuf_iterator
is:
a single-pass input iterator that reads successive characters from the
std::basic_streambuf
(ifs
in this example) object for which it was constructed... The default-constructedstd::istreambuf_iterator
is known as the end-of-stream iterator. When a validstd::istreambuf_iterator
reaches the end of the underlying stream, it becomes equal to the end-of-stream iterator.
content
is constructed from an iterator pair - the first one of which is our single-pass iterator into the file, and the second of which is the end-of-stream iterator that acts as a sentinel. The range [first, last)
that the string
constructor refers to is, in this case, the full contents of the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With