Reputation: 430
I have written a code where I tried to read a bmp file and write it to another file.When I try to write it an output file creates but it does not open . here is my code
#include<iostream>
#include<fstream>
using namespace std;
//int writeFile(string content);
int main() {
ifstream myReadFile;
ofstream myWriteFile;
myReadFile.open("D:/MIT_Database/barbara_gray.bmp");
myWriteFile.open("D:/MIT_Database/barbara_graywrite.bmp");
char output[100];
string content;
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
getline( myReadFile, content );
cout<<content;
// myReadFile >> output;
for(int i=0;i<content.length();i++)
{myWriteFile<<content[i];}
// myWriteFile<<content<<'\n';
myWriteFile<<'\n';
}
}
myReadFile.close();
myWriteFile.close();
return 0;
}
Upvotes: 0
Views: 929
Reputation: 311
fstream in("test.bmp",ios::binary|ios::in);
fstream out("new.bmp",ios::binary|ios::out);
char c;
while(!in.eof()) {
c=in.get();
out.put(c); }
in.close();
out.close();
Upvotes: 1