I have a file that consists of lines that look like this:
Alice 60 30 75
Bob 20 250 12
Where the name and integer lengths are variable. What's the shortest way to put the name into a string and the integers into an array of size 3? I did a getline() and then pushed the first char up to the first space into a char vector, transferred to string, then did the next char to space, converted using atoi() then sent to array, etc. I feel like there's probably a much better way?
I tried the suggestion line this:
int main() {
ifstream infile("wheelgame.txt");
string s;
vector<int> a(3);
while (cin >> s >> a[0] >> a[1] >> a[2])
{
cout << "test";
}
}
But I think I'm misunderstanding? It runs forever this way.