I’m currently working on “There Is No Spoon 1”.
Here’s the code I’m working with:
vector<vector<int>> graph;
// Read in each row of graph
for (int i = 0; i < rows; i++) {
string line;
vector<int> set;
getline(cin, line);
for(char & c : line) { set.push_back(c == '0' ? 1 : 0); }
graph.push_back(set);
}
Is there a way to read the input without saving it to line, or to any variable? It seems kind of pointless to have a variable when I don’t actually do anything with that variable. The only thing I do with it is read each character in it and then set something else to either a 1 or 0 depending on what it finds.
Essentially, what I want to do is something like this:
for (int i = 0; i < rows; i++) {
vector<int> set;
for(char & c : cin) { set.push_back(c == '0' ? 1 : 0); }
graph.push_back(set);
}
it doesn’t work that way, but is there a way to do something like that?