Re: Writing a <char> Array to Disk and Reading it in again
KevinSimonson <kvnsmnsn@hotmail.com> wrote:
On Oct 19, 3:01?pm, Luc Danton <lucdan...@free.fr> wrote:
Try #include <fstream>.
Great; thanks; I got it working.
Now how _would_ I write an integer to the <ofstream> object, and then
read the integer from the <ifstream> object, so that I could have
dynamically sized <char> arrays?
Based on this, and your other posts, I'm not sure if you even know
enough about the language to be able to communicate your problem
effectively. One thing you could try is to write the solution in some
other language and then post it asking how to do the same thing in C++.
This might help as well:
http://www.parashift.com/c++-faq-lite/serialization.html
Taking all of the above into account. My attempt to answer your question
is:
#include <fstream>
#include <vector>
int main() {
// write an integer to an ofstream object
std::ofstream os("save.txt");
os << 12;
os.close();
// read the integer from an ifstream object
int size = 0;
std::ifstream is("save.txt");
is >> size;
// make a dynamically sized char array
std::vector<char> arr(size);
assert(arr.size() == 12);
}