C++ - DO-WHILE에 의한 매크로 트랩핑

출처 #ifdef _DEBUG #define DEBUG_LOG(exp, ...) do {if (!(exp)){std::printf(__VA_ARGS__);}} while(0) #else #define DEBUG_LOG(exp, ...) do {(void)(exp);} while(0) #endif int main() { int x = 99; DEBUG_LOG(x > 100,"warning! x = %d", x); // x가 100 이하라면 경고를 표시 return 0;...
더 읽기

C++ - 문자열을 수치로 변환하는 방법

atoi #include <cstdlib> #include <iostream> #include <string> #include <typeinfo> int main() { const std::string str("123"); auto num = std::atoi(str.c_str()); std::cout << typeid(num).name() << " : " << num << std::endl; } strtol #include <cstdlib> #include <iostream> #include <string> #include <typeinfo>...
더 읽기