わびさびサンプルソース

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

ファイルのコピー

ifstreamとofstreamを利用してファイルをコピーします。

#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <fstream>



/*
	ファイルのコピー
*/
void copy_file
(
	  std::wstring oDstFilePath
	, std::wstring oSrcFilePath
)
{
	std::ifstream ifstr( oDstFilePath.c_str(), std::ios::binary );
	std::ofstream ofstr( oSrcFilePath.c_str(), std::ios::binary );

	// コピー
	ofstr << ifstr.rdbuf();
}



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

	// ファイルをコピーする
	copy_file( L"dst_file.txt", L"src_file.txt" );

	// 標準出力へ出力する
	std::wcout << L"ファイルをコピーしました。" << std::endl;

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

実行結果

ファイルをコピーしました。






わびさびサンプルソース

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