Using two date arrays

Hi

Like most people on this forum I'm teaching myself C++. This is my first post so hello everyone.

I have two date/time structures which I'm populating, but when I populate the second one it sets the same values in the first.

I appreciate I've missed something obvious here, but can someone help. This is what I've got so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    tm *FirstDate = gmtime(&now);
    tm *SecondDate = gmtime(&now);
    
    cout <<"Enter your first date in the format dd/mm/yyyy" << endl <<">";
    getline (cin,tempstring);
   
    FirstDate->tm_mday = atoi(tempstring.substr(0,2).c_str());
    FirstDate->tm_mon = atoi(tempstring.substr(3,2).c_str());
    FirstDate->tm_year = atoi(tempstring.substr(6,4).c_str());

// this is correct...
    cout<<" your first entered " <<FirstDate->tm_mday << "/" <<FirstDate->tm_mon <<"/" <<FirstDate->tm_year <<endl; 
    cout <<"Now enter your second date in the format dd/mm/yyyy" << endl <<">";
    getline (cin,tempstring2);

   
    SecondDate->tm_mday = atoi(tempstring2.substr(0,2).c_str());
    SecondDate->tm_mon = atoi(tempstring2.substr(3,2).c_str());
    SecondDate->tm_year = atoi(tempstring2.substr(6,4).c_str());
  
 // at this point they're both the same as the last entry.. 
     cout<<" your first entered " <<FirstDate->tm_mday << "/" <<FirstDate->tm_mon <<"/" <<FirstDate->tm_year <<endl; 
     cout<<" your second entered " <<SecondDate->tm_mday << "/" <<SecondDate->tm_mon <<"/" <<SecondDate->tm_year <<endl; 
 


What have I missed or misunderstood?

Cheers

Sam
Topic archived. No new replies allowed.