In turbo c++,how can i copy a certain file from one drive to the other e.g,the file is located in G:\one ,i want to copy it to C:\tc the file name is "file.txt"...Much love

1 Year
Discussion Span
Last Post by vijayan121

Don't know about Turbo C++. This is standard C++; it may work in Turbo C++ too.

// open the source file for input (text)
std::ifstream srce_file( "G:/one/file.txt" ) ; 
// or "G:\\one\\file.txt" if it is a really old version of Windows
// check for is_open() elided for brevity

// open the destination file for output (text), 
// truncate if it exists, create new otherwise
std::ofstream dest_file( "C:/tc/file.txt" ) ; 

// copy file
dest_file << srce_file.rdbuf() ;

As an aside, when C++17 turns up, the filesystem library will allow something like this:


Currently, you can make use of it through Boost.


The File System TS was published a couple of days back.

Final Draft: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4100.pdf

It is just a TS, so: 'This Technical Specification is applicable only to vendors who wish to provide the interface it describes.'

'Starting in 2012, the committee has transitioned to a "decoupled" model where major pieces of work can progress independently from the Standard itself and be delivered as separate TS's. Vendors can choose to implement these, and the community can gain experience with the std::experimental version of each feature.' - https://isocpp.org/std/status

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.