How to copy a binary file from a "input stream binary file"
Feb 15, 2008 at 3:11pm UTC
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 Feb 15, 2008 at 3:12pm UTC
Feb 15, 2008 at 9:22pm UTC
Your question is hard to understand.
Are you asking how to set cin to binary mode?
Feb 18, 2008 at 10:50am UTC
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
Feb 18, 2008 at 11:35pm UTC
For windows you could try:
_setmode( _fileno( stdin ), _O_BINARY );
For unix I believe you would remove the leading underscores.
Feb 19, 2008 at 10:22am UTC
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 Feb 19, 2008 at 10:23am UTC
Feb 19, 2008 at 6:42pm UTC
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.