Apr 23, 2014 at 12:08am UTC
Okay, so i'm trying to figure out how I would code copying a file that cannot be opened (eg. any file that isn't ANSII format).
I know that for a .txt or something like that I could simply do
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream FileToCopy;
ofstream CopiedFile;
string linetocopy;
FileToCopy.open("Test.txt" );
CopiedFile.open("Copy_Of_Test.txt" );
while (!FileToCopy.eof())
{
getline(FileToCopy,linetocopy);
CopiedFile << linetocopy << endl;
}
FileToCopy.close();
CopiedFile.close();
return 0;
}
But could anyone help point me into the right direction of how I would copy a file's contents into a char buffer and copy it over to another file for files that can't be opened/read in notepad? (Example: a rar file or a .exe ) Not sure if that makes any sense, please let me know if I need to clarify.
Last edited on Apr 23, 2014 at 12:09am UTC
Apr 23, 2014 at 12:30am UTC
Thanks James for the clear and awesome response.
Next question I have:
Is there a way to just copy a part of that Input stream and copy it in chunks to the other file, or is what i'm trying not possible?
Edit: Nevermind I am reading the link you posted now thanks.
Last edited on Apr 23, 2014 at 12:33am UTC