Stxxl  1.4.0
containers/copy_file.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  containers/copy_file.cpp
00003  *
00004  *  copies a file to another file
00005  *
00006  *  Part of the STXXL. See http://stxxl.sourceforge.net
00007  *
00008  *  Copyright (C) 2004-2006 Roman Dementiev <dementiev@mpi-sb.mpg.de>
00009  *
00010  *  Distributed under the Boost Software License, Version 1.0.
00011  *  (See accompanying file LICENSE_1_0.txt or copy at
00012  *  http://www.boost.org/LICENSE_1_0.txt)
00013  **************************************************************************/
00014 
00015 #include <stxxl/io>
00016 #include <stxxl/vector>
00017 
00018 typedef unsigned char my_type;
00019 
00020 
00021 using stxxl::syscall_file;
00022 using stxxl::file;
00023 
00024 int main(int argc, char * argv[])
00025 {
00026     if (argc < 3)
00027     {
00028         std::cout << "Usage: " << argv[0] << " input_file output_file " << std::endl;
00029         return -1;
00030     }
00031 
00032     unlink(argv[2]);                                            // delete output file
00033 
00034     syscall_file InputFile(argv[1], file::RDONLY);              // Input file object
00035     syscall_file OutputFile(argv[2], file::RDWR | file::CREAT); // Output file object
00036 
00037     typedef stxxl::vector<my_type> vector_type;
00038 
00039     std::cout << "Copying file " << argv[1] << " to " << argv[2] << std::endl;
00040 
00041     vector_type InputVector(&InputFile);                        // InputVector is mapped to InputFile
00042     vector_type OutputVector(&OutputFile);                      // OutputVector is mapped to OutputFile
00043 
00044     std::cout << "File " << argv[1] << " has size " << InputVector.size() << " bytes." << std::endl;
00045 
00046     vector_type::const_iterator it = InputVector.begin();       // creating const iterator
00047 
00048 
00049     for ( ; it != InputVector.end(); ++it)                      // iterate through InputVector
00050     {
00051         OutputVector.push_back(*it);                            // add the value pointed by 'it' to OutputVector
00052     }
00053 
00054 
00055     return 0;
00056 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines