mardi 27 février 2018

Parse cmd input with fewer lines of code

Can I do (1) and/or (2) better with something from algorithm for example? By better, I mean with more readable code and with fewer lines of code. I really don't like that I need so many lines of code to do this... Thank you.

for (int node = 0; node < numberOfNodes; ++node)
{
    cout << node << ": ";
    // (1)
    string input;
    getline(cin, input);
    istringstream ss(input);

    // (2)
    vector<int> adjacencyList;
    int adjacent;
    while (ss >> adjacent)
    {
        adjacencyList.push_back(adjacent);
    }
    graph[node] = adjacencyList;
}

Aucun commentaire:

Enregistrer un commentaire