Sto cercando di usare un fast input, ma crasha sempre nello stesso punto. Quando arriva all’ultima parola, se e solo se non c’e’ nulla dopo (spazi o a capo), va in loop/crasha. Questo e’ il codice, mettendo per esempio un 4 in un file di input di nome input.txt, senza spazi o niente dopo, va in loop, e provando a inserire una nuova linea, funziona. Grazie in anticipo, ed un altra domanda, avete consigli sul fast output, serve a qualcosa? e se serve come si fa?
#include <iostream>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
#define BUFFER_SIZE 500
struct Edge {
int to, weight;
bool flag;
};
char _buffer[BUFFER_SIZE];
int _buf_pointer;
int _buf_size;
int _fd;
void loadBuffer() {
_buf_size = read(_fd, _buffer, BUFFER_SIZE);
_buf_pointer = 0;
}
int readint() {
int n = 0;
char c;
do {
c = _buffer[_buf_pointer++];
if (_buf_pointer >= _buf_size) loadBuffer();
if (c >= '0' && c <= '9')
n = n*10 + (c-'0');
} while (c >= '0' && c <= '9');
return n;
}
int main() {
ios::sync_with_stdio(false);
_fd = open("input.txt", O_RDONLY);
loadBuffer();
int x = readint();
cout<<x<<endl;
return 0;
}