わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。

wsprintfでワーニングC4996が出ない代替関数

wsprintfを使うとwarning C4996が出る事があります。これを回避する関数は _swprintf_pとなります。

#include <tchar.h>
#include <string>
#include <iostream>
#include <fstream>
#include <windows.h>



int _tmain
(
	  int argc
	, _TCHAR* argv[]
)
{
	// 標準出力へユニコードを出力する
	setlocale( LC_ALL, "Japanese" );

	TCHAR waBuf[ 512 ];

	// wsprintfの代替関数
	_swprintf_p( waBuf, _countof( waBuf ), L"%s", L"warning C4996は出ません!!" );

	// 結果を出力
	std::wcout << waBuf << std::endl;

	// 正常終了
	return( 0 );
}

実行結果

warning C4996は出ません!!






わびさびサンプルソース

WindowsやHTML5などのプログラムのサンプルコードやフリーソフトを提供します。