I'm trying to duplicate files by using an ifstream to read the file and ofstream to write back out, but having some problems. Here's what I have so far:
std::ifstream File(_str.c_str(), std::ios::binary);
std::string strFile;
strFile.assign( (std::istreambuf_iterator<char>(File) ),
(std::istreambuf_iterator<char>() ) );
File.close();
return strFile;
What's happening is some values of the string are null, and the string is terminating right there. For example if it was
1 'h'
2 'i'
3 0
4 'h'
5 'i'
it would return simply "hi"
I have tried various for loops and ways of getting around this, for example replacing the 0's with spaces, and replacing the 0's with "-NULL-" then on the user side replacing "-NULL-" back with 0 again, but I can't seem to add 0 to the string.
Could anyone give me some tips for what I could do to get around this problem? What I'm trying to do is transfer a .png via UDP, which is why I'm chucking the file into a string
Cheers!