본문 바로가기
C++/C++ Common

가변 인수 매크로

by doublerabbits 2023. 3. 30.

 

#include "pch.h"

#pragma warning(disable: 4793) // methods are compiled as native (clr warning)

#include <stdio.h>
#include <stdarg.h>
#include <iostream>
#include <string>


using namespace std;
using namespace System;

#define Log(fmt, ...) _log(__FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)

void _log(const char* filePath, const char* funcName, const int lineNum, const char* fmt, ...);

void ShowQwerty();
void ShowNumber();

int main()
{
    ShowQwerty();
    ShowNumber();

    std::string str;
    std::getline(std::cin, str);

    return 0;
}

void _log(const char* filePath, const char* funcName, const int lineNum, const char* fmt, ...)
{
    va_list ap;
    va_start(ap, fmt);
    cout << "[" << filePath << " " << funcName << " " << lineNum << "] ";
    vprintf(fmt, ap);
    cout << endl;
    va_end(ap);
}

void ShowQwerty()
{
    Log("qwerty");
}

void ShowNumber()
{
    int num = 12345;
    Log("%d\n", num);
}

 

 

'C++ > C++ Common' 카테고리의 다른 글

Endian 변환  (0) 2024.06.26
함수 결과 처리 코드 간소  (0) 2024.05.29
Time  (0) 2023.03.30
Bit Shift  (0) 2023.03.27
시간 출력  (0) 2022.11.05