hi all, C++ beginner needs help.

I decided today to give C++ FileIo Streams a little go. since I not played with them much before and have not started out very well

anyway I desided to make a little project that can save the contents of a struct to a file. pretty basic in fact.

My problum is reading back the info. the letter and number displays ok but for some reason str is not. anyway I left my code below if that helps.

VB Code:
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. struct test
  6. {
  7.     int number;
  8.     char letter;
  9.     char *str;
  10. } aTest;
  11.  
  12.  
  13. int main(int agvc)
  14. {
  15.     ofstream fout;
  16.     ifstream fin;
  17.     // fill struct with some random data
  18.     aTest.number = 245;
  19.     aTest.letter = 'A';
  20.  
  21.     //What am I doing wrong here I wonder
  22.     aTest.str = (char*) malloc(100);
  23.     strcpy(aTest.str,"Hello World this is a long string");
  24.  
  25.  
  26.     //write the struct to the file
  27.    
  28.     fout.open("C:\\test.txt",ios::binary);
  29.     fout.write((char*)(&aTest),sizeof(aTest));
  30.     fout.close();
  31.    
  32.     // Clear struct of it's data I am only new in C++
  33.     // So i am not sure this is the correct way to clear stuff out
  34.     // tho for the example it be ok I think
  35.     aTest.letter = '\0';
  36.     aTest.number = 0;
  37.     strcpy(aTest.str,"\0");
  38.     //Load the struct back in so we can display the data
  39.  
  40.     fin.open("c:\\test.txt",ios::binary);
  41.     fin.read((char*)(&aTest),sizeof(aTest));
  42.     fin.close();
  43.  
  44.     // display the data
  45.     std::cout << "Number: " << aTest.number << "\n";
  46.     std::cout << "Letter: " << aTest.letter << "\n";
  47.     std::cout << "String: " << aTest.str << "\n"; // :( why is my str not showing
  48.  
  49. }

anyway hope someone can help
Thanks.