Copy on file to another file in c++

Open a file, read everything from it. Write everything you read to new file.

Or simply?

#include <windows.h>

int main()
{
  CopyFile( "source", "destination", true );
}

Or simply?

#include <windows.h>

int main()
{
  CopyFile( "source", "destination", true );
}

Providing your developing on a windows machine and want unportable code.

>Providing your developing on a windows machine and want unportable code.
Fair enough ;)

#include <fstream>

int main()
{
  std::ifstream in( "source", std::ios::in );
  std::ofstream out( "target", std::ios::out );
  out << in.rdbuf();
}

Shortest portable way I can think of.

>Providing your developing on a windows machine and want unportable code.
Fair enough ;)

#include <fstream>

int main()
{
  std::ifstream in( "source", std::ios::in );
  std::ofstream out( "target", std::ios::out );
  out << in.rdbuf();
}

Shortest portable way I can think of.

fair enough, now all thats leftfor me to pull you up on is your lack of a return :D

Chris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.