Hello, I'm currently trying to figure out how I could go about taking a getline putting the one line into an array and then putting the first value aka array[o] into a command variable and then all the next values on the line into seperate variables of integer for key value and string for assosciated data that are linked to each other.
I figure I would use https://en.wikipedia.org/wiki/Hash_map_%28C%2B%2B%29 #include <unordered_map> from this page.
I can't seem to figure out how I would go about this.
while(!inputFile.eof() ) {
getline (inputFile, line);
array[i] = line;
i++;
}
if(array[i] == "B"){
// do function for B with data (key, assosciateData)
}
Is my code so far. I take the input and put it into the array for however many lines where i = 0. Then I was thinking I would make an if else statement where it chooses the command variable i.e. if "B" do this function if "C" do this function
My input looks like this. "C 129.2 hi 69.8 This 38.9 World"
so I'm trying to make it where "C" = Command, 129.2 = key, hi = assosciatedData. As shown below:
std::unordered_map<std::string, int> junk;
junk["hi"] = 129.2;
junk["This"] = 69.8;
My main problem is there are multiple lines on the input file that go into array[i], so I can't just choose to do the first line and choose the first letter as the command (at least I don't know how to") cause when I do array[0] I would just get the whole line "C 129.2 hi 69.8 This 38.9 World", and I'm a bit at a loss of how to seperate them. Thanks guys.