How to copy a binary file from a "input stream binary file"

Hi...
i must make a copy file from a streaming input so i make two file:
The first script copy from a straming file (from Redmon) to in a simple file and it work correctly...but when i send a binary file it tunk the file.
This is my code:
1
2
3
4
5
6
7
8
9
10
11
//PART OF CODE THAT WORK CORRECTLY
    string pathTmp="C:\\test.txt";
    cout << pathTmp;
    fstream myfile;
    myfile.open ( pathTmp.c_str(), ios::out | ios::app | ios::binary );
    char ch;
    while( cin.get(ch)){
      myfile.put(ch);
    }
    myfile.close();
    return 0;[code]

[/code]

So i make a script that from a argv input file and output file copy the binary file!!And also this run correctly:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <fstream>
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[])
{
  FILE *in,*out;
     in = fopen( argv[1], "r" );
     out = fopen( argv[2], "w" );
    
     std::ifstream ifs(argv[1], std::ios::binary);
     std::ofstream ofs(argv[2], std::ios::binary);
     ofs << ifs.rdbuf();[code]
  return 0;
}


Now i need to integrate the second script in the first...:-)
so from a streaming file in input i must redirect in a second "binary"file...help me...
bye & thank's
Last edited on
Your question is hard to understand.
Are you asking how to set cin to binary mode?
Sorry for my English...however if exist a method to set cin for copy stream in binary mode can you tell me how??
thanks Dirk
bye
For windows you could try:

 
    _setmode( _fileno( stdin ), _O_BINARY );


For unix I believe you would remove the leading underscores.
Sorry...i have this code:

1
2
3
4
5
6
7
8
9
10
    string pathTmp="C:\\test.txt";
    cout << pathTmp;
    fstream myfile;
    myfile.open ( pathTmp.c_str(), ios::out | ios::app | ios::binary );
    char ch;
    while( cin.get(ch)){
      myfile.put(ch);
    }
    myfile.close();
    return 0;[code]


Where i must insert the string _setmode( _fileno( stdin ), _O_BINARY );

Thank you
bye
Last edited on
Put this with your includes:

1
2
#include <io.h>
#include <fcntl.h> 


and put the _setmode() call at the beginning of your code.
Topic archived. No new replies allowed.