Hello, I need help with writing a quick read from a file with getchar_unlock (). There are two lines in the file that are not necessarily the same size, how many characters in each line are also not known, you need to count them in 2 arrays or vectors, thanks in advance for your help.
Problem: the code reads only 1 number, I don’t know how to do it for the whole line
#include <iostream> using namespace std; bool read_int_unlocked(int & out) { int c = getchar_unlocked(); int x = 0; int neg = 0; for (; !('0'<=c && c<='9') && c != '-'; c = getchar_unlocked()) { if (c == EOF) return false; } if (c == '-') { neg = 1; c = getchar_unlocked(); } if (c == EOF) return false; for (; '0' <= c && c <= '9' ; c = getchar_unlocked()) { x = x*10 + c - '0'; } out = neg ? -x : x; return true; } int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int number; while(read_int_unlocked(number)) std::cout << number << " "; return 0; }