The fastest way to read a file line by line with an arbitrary number of characters in each

Ok, I'm trying to figure out which way will be faster to read the text file I'm working with. The contents of the file are as follows:

1982 3923 3542 4343
2344 3453 2
334 423423 32432 23423

Basically this is just an arbitrary number of int numbers, and I need to read line by line. Would it be better to use getline or the input operator (→)? I personally think that it would be much easier to implement using the insert operator, but I do not know how to make the program read all int numbers on one line until it reaches the end. I thought to configure it as follows:

ifstream input;
input.open("someFile.txt");
if (input) {
    char* ch;
    while (ch != '\n\)
        getline(input, buffer, ' ')

, int, int . - , int int. !

+3
2

:

ifstream in(...);
string line;
while (getline(in, line)) {
    istringstream line_in(line);
    while (line_in) {
        int val = 0;
        if (line_in >> val) {
            // Do something with val
        }
    }
    // eol
}
+5
  • , .
  • . .
  • , , . , .

. , .

+2

Source: https://habr.com/ru/post/1722544/


All Articles