Results 1 to 6 of 6

Thread: saving an array to file

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    How can i save an array to a file? Thanks guys

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    try this:
    Code:
    char** MyArray = {"Hi there", "And again", "Different"};
    
    ofstream MyFile("c:\myfile.txt");
    
    for(int i = 0; i < 3; i++) {
        MyFile << MyArray << endl;
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    sorry Im pretty new to C++ but what does char** do?

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Sorry...well, a pointer to char is char*, which means that:
    Code:
    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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    so Char** me = "Hello" would get "He"?

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

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    No. char** me would give an error...
    Code:
    char* it = "It's string";
    char* that = "Another string";
    char** both = {it, that};
    Do you get the picture? Likewise:
    Code:
    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:
    Code:
    cout << all[0][0][0] << endl;
    to print "It's string"
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width