I'm pretty new to cpp and I've been struggling on this for hours, none of my research attempts were lucky.
I have a few .txt files with the following structure:
07.07.2021 23:11:23 01
08.07.2021 00:45.44 02
...
I want to create two arrays, one containing the dates and one containing the times. However all I've accomplished so far are arrays containing the last element of each column and the rest is empty (Example see below). The Code looks like this:
std::vector<string> txt_to_time(std::ifstream raw, int num, int what){
std::vector<string> date(num);
std::vector<string> time(num);
std::vector<string> irrelevant(num);
string str;
for (int i=0; i<num; i++)
{
while (std::getline(raw,str))
{
raw >> date[i] >> time[i] >> irrelevant[i];
}
}
if (what == 0)
{
return time;
}
return date;
}
I think I am messing something up in the while-loop but I don't really know how to fix it.
When I try to print every element of the vector the output I get is
10:45:22
(int) 0
Thanks for spending time to read my question, every answer is appreciated!