vector-of-bool / cmrc

A Resource Compiler in a Single CMake Script
MIT License
674 stars 74 forks source link

How do I use the data from a cmrc::resource? #6

Closed Tetrago closed 6 years ago

Tetrago commented 6 years ago

I tried to use: cmrc::resource file = cmrc::open(file); std::string data(file.begin(), file.end()); But there is no string constructor like this. How do I use CMakeRC?

Tetrago commented 6 years ago

Actually, I can't even get CMakeRC to run, it errors out.

vector-of-bool commented 6 years ago

Sorry for the delay. Were you able to work out a solution?

izzyreal commented 3 years ago

I do

auto file = fs.open("some_resource_file.txt")
auto it = file.begin();

vector<char> bytes;

do bytes.push_back(*it);
while (it++ != file.end());
izzyreal commented 3 years ago

But DarthGandalf has a better (C++ 17) syntax in https://github.com/vector-of-bool/cmrc/issues/24. Comes down to:

auto file = fs.open("some_resource_file.txt")
char* data = std::string_view(file.begin(), file.end() - file.begin()).data();