Dieser Code macht das:
#include <any>
#include <format>
#include <iostream>
#include <memory>
#include <vector>
#include <string>
class c_stream_ctrl {
public:
c_stream_ctrl() {};
~c_stream_ctrl() {};
bool is_input_valid(std::string_view input) {
return (!input.empty() && input.size() < input.max_size());
}
template<typename ... t>
__forceinline void print(std::string_view fmt, bool insert_newline, t... args) {
std::string formatted_str{ };
_args.push_back(args...);
if (!_args.empty())
formatted_str = std::format(fmt, args...);
else
formatted_str = fmt;
if (is_input_valid(formatted_str)) {
for (auto& c : formatted_str)
std::cout << c;
if (insert_newline)
std::cout << '\n';
}
}
template<typename t>
__forceinline void get(t& arg) {
std::cin >> arg;
_args.push_back(arg);
}
private:
std::string _fmt{ };
std::vector<std::any> _args{ };
};
int main() {
const auto ctrl = std::make_unique<c_stream_ctrl>();
std::string input;
ctrl->get(input);
ctrl->print("Hallo {}", false, input);
}