Skip to content

Instantly share code, notes, and snippets.

@brandonprry
Created December 3, 2024 20:55
Show Gist options
  • Save brandonprry/b2cecc09973533d8ec24336c5059ced4 to your computer and use it in GitHub Desktop.
Save brandonprry/b2cecc09973533d8ec24336c5059ced4 to your computer and use it in GitHub Desktop.
uint8_t* readAllStdin(size_t& length) {
std::vector<uint8_t> buffer;
char temp;
// Read all input data from stdin
while (std::cin.get(temp)) {
buffer.push_back(static_cast<uint8_t>(temp));
}
// Allocate memory for the buffer and copy the data
length = buffer.size();
uint8_t* data = new uint8_t[length];
std::copy(buffer.begin(), buffer.end(), data);
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment