PDA

Click to See Complete Forum and Search --> : saving an array to file


SteveCRM
Aug 22nd, 2000, 12:53 AM
How can i save an array to a file? Thanks guys ;) :D

parksie
Aug 22nd, 2000, 01:42 PM
try this:

char** MyArray = {"Hi there", "And again", "Different"};

ofstream MyFile("c:\myfile.txt");

for(int i = 0; i < 3; i++) {
MyFile << MyArray << endl;
}

SteveCRM
Aug 22nd, 2000, 05:01 PM
sorry Im pretty new to C++ but what does char** do?

parksie
Aug 22nd, 2000, 05:08 PM
Sorry...well, a pointer to char is char*, which means that:

char* me = "Hello";

me now points to the first character, and (*me), when dereferenced, is equal to 'H'. If you add another *, then you are taking a pointer to a pointer to char, basically getting a multidimensional array.

SteveCRM
Aug 22nd, 2000, 05:14 PM
so Char** me = "Hello" would get "He"?

sorry I just wanted to make sure it wasn't math...

parksie
Aug 22nd, 2000, 05:24 PM
No. char** me would give an error...

char* it = "It's string";
char* that = "Another string";
char** both = {it, that};

Do you get the picture? Likewise:

char* it = "It's string";
char* that = "Another string";
char** both = {it, that};
char** opp = {that, it};
char*** all = {both, opp};

then I can do:

cout << all[0][0][0] << endl;

to print "It's string"