Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
std::string
#include <iostream> #include <string> typedef struct string { union { const char buf[16]; const char *ptr; } bx; uint32_t size; uint32_t res; } string; const char* read_str(const std::string& str) { const auto strptr = (const string*) &str; if(strptr->size > 15) return strptr->bx.ptr; return strptr->bx.buf; } int main() { std::string str1 = "this is a very large string that is more than 15 charactes!"; printf("test 1: %s\n", read_str(str1)); std::string str2 = "small one"; printf("test 2: %s\n", read_str(str2)); std::string str3 = "this is a very large string that is more than 15 charactes!"; str3 = "small one"; printf("test 3: %s\n", read_str(str3)); }
run
|
edit
|
history
|
help
0
Competitive - Algorithm for max number of superior characters
const_pointer_cast
Sum of numbers in a series using sum formular
Build char string (multibyte) with wchar
move swap
rang_warnings
Integral constant
#9
DCapSurfaceDesc
Time Zone Registry