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
Use std::is_base_of to subset STL container contents.
msvc set-terminate
#26
define own struct
Regex failure
Fast sine to fill array (sin/cos pair)
C++ exception
VC++ latest rejects istream to nullptr comparison
why fatal error C1083
const_pointer_cast