have been reading "thinking in c++" to see if i could find out why iostreem is returning all "0" zeros. had #include<fstream> and #include<iostream> . thought it was a header problem. so i added include<cstdio> and #include<cstdlib> . i want to read two files in binary and write one file in binary.
Code:
// sidebysidesecuritycampicture.cpp
#include<cstdio>
#include<cstdlib>
#include<fstream>
#include<iostream>
using namespace std;
int imageone[2000000] ; // first security camera
int imagetwo[2000000] ; // second security camera
int imagethree[2000000] ; // sidebysideimages out
int main() {
int b; // imageone line in for later use
int d; // imagetwo line in for later use
int e; // line one from image one and line one from image2 together put in later
ifstream in ("picture1.bmp" , ios::binary ) ;
ifstream twoin ("picture2.bmp" , ios::binary) ;
ofstream out ("sidebysidepicture1.bmp" , ios::binary) ;
printf( "sizeif in == %d " , sizeof(in) ); //debug check file size
// load file imageone.bmp from disk to ram
for(int a = 0 ; a < 2000000 ; a++) {
in >> imageone[a] ;
cout << imageone[a] << " " << a << endl ; //debug check what is going to image one in ram
} // end fill for
for(int a = 0 ; a < 2000000 ; a++) {
twoin >> imagetwo[a] ;
cout << imagetwo[a] << " " << a << endl ; // debug check what is going to image two in ram
} // end fill for
for(int a = 0 ; a < 64 ; a++ ) {
out << imageone[a]; // copy header of file picture one
cout << imageone[a]<< " " << a << endl ; // check what is going out to file sidebysidepicture1.bmp
}
// next part read file 1 then file 2 and writes to sidebysidepicture1.bmp
....
for(int a = 65 ; a < 2000000 ; a++ ) {
out << imagethree[a] ;
cout << imagethree[a] << " " << a << " " << e << endl ;
} // end for moved
// fclose(in);
// fclose(twoin);
// fclose(out);
} // end main
finished image will be two pictures side by side. will go back finish header edit of image width later. next issue is sizeof(in) return 252 bytes and not 2000000. meow. another issue is i get errors with fclose(). i know iostream closed files for you. thought the file was not closing properly so i put that in there. then added the debug lines to find out that it is not even reading the files. then added ios::binary to the streams.
it should at least copy the header at this point. have done many times in c but not cpp.
tia.