Question: So I'm writing a function to read a file and put its content into another file. Here's what I've got so far:

```
void myFile::printWords(string input, string output) {
 ifstream file(input.c_str());
 ofstream file_out(output.c_str());
 string word;

 if(!file.is_open())
 {
  printf("File can't be opened\n");
  exit(o);
 }
 while(file >> word) {
  cout<< word << '\n';
 }
 file.close();

}

```

Question is how do I proceed with writing to a file?

Answer: 
You don't quite need iostreams to copy files; you just need raw stream buffers. For example, here's a complete copy program:

```
#include <algorithm>   // for std::copy
#include <cstdlib>     // for EXIT_FAILURE
#include <fstream>     // for std::filebuf
#include <iterator>    // for std::{i,o}streambuf_iterator

int main(int argc, char *argv[])
{
    if (argc != 3) { return EXIT_FAILURE; }

    std::filebuf infile, outfile;
    infile.open(argv[1], std::ios::in | std::ios::binary);
    outfile.open(argv[2], std::ios::out | std::ios::binary);

    std::copy(std::istreambuf_iterator<char>(&infile), {},
              std::ostreambuf_iterator<char>(&outfile));
}

```
rather than doing this on a word to word bassis, which doesn't work weel with whitespaces, you could (if you really waht to use c++) use a char[] dump of the file

```
std::fstream ifile(input.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
std::fstream ofile(output.c_str(), std::ios::out | std::ios::binary);

if (!(ifile.is_open() && ofile.is_open())) { handle_error(); }

size_t size   = ifile.tellg();
char*  buffer = new char[size];

ifile.seekg(0, std::ios::beg);
ifile.read(buffer, size);
ofile.write(buffer, size);

ifile.close();
ofile.close();

```

Still it would make much more sense to use your OS functionality