C++输出到Output窗口

每次都不能直接搜索到C++输出到Output窗口的有效全部代码,故而自己写出来直接用 TraceOutput 和 TraceOutputW 即可

这是输出两参数的

#include 

	static wchar_t* CastToWideChar(const char* pszMultiByte)
	{
		int iSize;
		wchar_t* pwszUnicode;
		
		iSize = MultiByteToWideChar(CP_ACP, 0, pszMultiByte, -1, NULL, 0);
		pwszUnicode = (wchar_t *)malloc(iSize * sizeof(wchar_t));
		MultiByteToWideChar(CP_ACP, 0, pszMultiByte, -1, pwszUnicode, iSize);
		return pwszUnicode;
	}

	static void TraceOutput(const char* format, const char* parameter)
	{
		int length1 = strlen(format);
		int length2 = strlen(parameter);
		int length = length1 + length2 + 1;
		wchar_t *buffer = new wchar_t[length];

		swprintf_s(buffer, length, CastToWideChar(format), CastToWideChar(parameter));
		OutputDebugString(buffer);

		delete buffer;
		buffer = NULL;
	}

	static void TraceOutputW(const wchar_t* format, const wchar_t* parameter)
	{
		int length1 = wcslen(format);
		int length2 = wcslen(parameter);
		int length = length1 + length2 + 1;
		wchar_t *buffer = new wchar_t[length];

		swprintf_s(buffer, length, format, parameter);
		OutputDebugString(buffer);

		delete buffer;
		buffer = NULL;
	}

还有写个不限输出参数的,下次再发

你可能感兴趣的:(C++,C++,Debug,Output)