#include <iostream>
#include <string>
#include <cstring>
using namespace std;
void c_function(char * dest) {
strcpy(dest, "FOOO");
}
template<std::size_t max>
struct string_filler {
char data[max+1];
std::string & destination;
string_filler(std::string & d) : destination(d) {
data[0] = '\0'; // paranoia
}
~string_filler() {
destination = data;
}
operator char *() {
return data;
}
};
int main() {
string foo;
c_function(string_filler<80>{foo});
cout << "foo contains \"" << foo << "\"" << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgY19mdW5jdGlvbihjaGFyICogZGVzdCkgewoJc3RyY3B5KGRlc3QsICJGT09PIik7Cn0KCgp0ZW1wbGF0ZTxzdGQ6OnNpemVfdCBtYXg+CnN0cnVjdCBzdHJpbmdfZmlsbGVyIHsKICBjaGFyIGRhdGFbbWF4KzFdOwogIHN0ZDo6c3RyaW5nICYgZGVzdGluYXRpb247CiAgc3RyaW5nX2ZpbGxlcihzdGQ6OnN0cmluZyAmIGQpIDogZGVzdGluYXRpb24oZCkgewogICAgZGF0YVswXSA9ICdcMCc7IC8vIHBhcmFub2lhCiAgfQogIH5zdHJpbmdfZmlsbGVyKCkgewogICAgZGVzdGluYXRpb24gPSBkYXRhOwogIH0KICBvcGVyYXRvciBjaGFyICooKSB7CiAgICByZXR1cm4gZGF0YTsKICB9Cn07CgppbnQgbWFpbigpIHsKCXN0cmluZyBmb287CgljX2Z1bmN0aW9uKHN0cmluZ19maWxsZXI8ODA+e2Zvb30pOwoJY291dCA8PCAiZm9vIGNvbnRhaW5zIFwiIiA8PCBmb28gPDwgIlwiIiA8PCBlbmRsOwoJcmV0dXJuIDA7Cn0=