By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,507 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,507 IT Pros & Developers. It's quick & easy.

Writing binary data (CString) to file

P: n/a
I have some binary data encoded as Base64 encoding in an XML element
like this:

<data>TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx</data>

how can I extract this data -
TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx

and save to a file say test2.xml

==================
pug::xml_node_list CategoryEntries;
PictureEntries[i].all_elements_by_name("category", CategoryEntries);

// if found XML element
if (CategoryEntries.size() 0) {
for (unsigned int i = 0; i < CategoryEntries.size(); i++) {

//extract the Base64 string from XML element
//this Base64 string has binary data after decode
CString cat = CategoryEntries[i].child(0).value();

//decode Base64 string into binary data
CString decoded = decodeBase64(cat);

//open file to write the binary data
std::ofstream file1("c:/test2.xml");

// write the decoded binary data to file
file1.write(decoded);

}
}
Nov 19 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.