I came from C so I'm trying to understand C++ input.
I want to read lines of input like so:
3
0 0 1 0
1 4 0 1
0 1 2 3
where 3 is the number of input lines I'm going to read next. My code is
#include<iostream>
#include<string>
int main() {
int n, k = 8;
std::cin >> n;
char lines[n][k];
for(int i = 0; i < n; i++)
std::cin.getline(lines[i], k);
}
I should be able to read the n
lines (because of the zeroth iteration) but it only goes for n-1
, so it finishes the reading at n-2
. I don't understand why and how to deal with it and properly read input like this.
Also: how would I do if I wanted to read the same way for a std::string
? Would I use std::string *lines[n];
?