Read from cin without saving to a variable?

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?

You can read one character at a time in cin. But you can’t use the foreach syntax since cin does not declare any iterator functions.

You can do something like this:

char c;
cin >> c;
while (c != '\n') {
    set.push_back(c == '0' ? 1 : 0);
    cin >> c;
}

if you know the length, you can also do this:

for (int n = 0; n < length; ++n) {
    char c;
    cin >> c;
    set.push_back(c == '0' ? 1 : 0);
}
cin.ignore(); // You have to clear out the remaining \n or you'll read it next time you read cin