我正在使用GetLocalTime(&time)
函數來獲取時間visual C++
。現在,我需要將輸入變高時的時間保存在另一個結構中,以便我可以對保存的時間進行進一步計算。如何在另一個結構中保存GetLocalTime時間
SYSTEMTIME time;
if(input==high)
{
count++; //Incrementing a counter to count the number of times input is high
//Depending upon this count, I need to save value of time in a new variable
//using GetLocalTime to get current time
GetLocalTime(&time);
}
如何根據計數值存儲當前時間。就像計數爲1時一樣,這意味着首次輸入爲高,因此將其存儲在a1
中。如果計數爲2,則存儲時間爲a2
。如果計數爲5,則存儲時間爲a5
。我不能使用開關,因爲案件不是固定的,可能有很多數量。我可以使用什麼其他邏輯來節省時間。
使用容器?例如'array','vector'等 – Rotem
@Rotem當count爲1時,我在數組中保存了時間,但當count爲2時它將覆蓋第一次的值。 ?或者可能是我沒有得到你想說的話。 –
如果您使用'count'作爲數組的索引,或者改爲使用'vector :: push_back',則不適用。 – Rotem