EEEEEEEEEEEEEEEEEEE
aababcdabcdeEEEEEEE
EEEEEEEEEEEEEEEEEEE
abcdeEEEEEEEEEEEEEE
#include <algorithm>
#include <iostream>
#include <memory_resource>
void Printer(char* buffer, std::string_view title) {
std::cout << title << '\n';
auto buff = std::string_view(buffer, 256);
for (const auto& ch : buff) {
if (ch >= ' ' ? ch : '_') {
std::cout << ch;
}
}
std::cout << " !endof buffer! \n";
}
int main () {
// A small buffer on stack
char buffer[256] = {};
std::fill_n(std::begin(buffer), std::size(buffer)-1, '#');
std::cout << buffer << '\n';
Printer(buffer, "Empty buffer:");
std::pmr::monotonic_buffer_resource pool{std::data(buffer), std::size(buffer)};
std::pmr::vector<std::pmr::string> vec{&pool};
vec.reserve(4);
vec.emplace_back("Hello Darkness");
vec.emplace_back("My Old Friend");
Printer(buffer, "Tree string in:");
vec.emplace_back("This is a longer string so what will happen now ????? well it will not");
Printer(buffer, "Long string:");
vec.emplace_back("1234");
Printer(buffer, "saved on buffer again");
}
###############################################################################################################################################################################################################################################################
Empty buffer:
############################################################################################################################################################################################################################################################### !endof buffer!
Tree string in:
��Q"���Q"�Hello Darkness#��Q"��Q"�
My Old Friend################################################################################################################################################################################# !endof buffer!
Long string:
��Q"���Q"�Hello Darkness#��Q"��Q"�
My Old Friend##��Q"�p�Q"�GG################################################This is a longer string so what will happen now ????? well it will not####################### !endof buffer!
saved on buffer again
��Q"���Q"�Hello Darkness#��Q"��Q"�
My Old Friend##��Q"�p�Q"�GG########��Q"�`�Q"�1234###########This is a longer string so what will happen now ????? well it will not####################### !endof buffer!
###############################################################################################################################################################################################################################################################
Empty buffer:
############################################################################################################################################################################################################################################################### !endof buffer!
Tree string in:
�bAd�Hello Darkness#�bAd�
My Old Friend################################################################################################################################################################################################# !endof buffer!
Long string:
�bAd�Hello Darkness#�bAd�
My Old Friend##�~@GG####################################################################################################################################################################### !endof buffer!
saved on buffer again
�bAd�Hello Darkness#�bAd�
My Old Friend##�~@GG########�bAd�1234########################################################################################################################################## !endof buffer!