わびさびサンプルソース

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

ファイルのコピー

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

ファイルのコピー
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#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などのプログラムのサンプルコードやフリーソフトを提供します。