how to read extreme long lines from text file fast and safe in C++?

后端 未结 3 1087
逝去的感伤
逝去的感伤 2021-01-04 20:37

There is a large text file of 6.53 GiB. Each line of it can be a data line or comment line. Comment lines are usually short, less than 80 characters, while a data line conta

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 20:55

    Well, the C standard library is a subset of the C++ standard library. From n4296 draft from C++ 2014 standard:

    17.2 The C standard library [library.c]

    The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to ensure static type safety.

    So provided you explain in a comment that a performance bottleneck requires it, it is perfectly fine to use fgets in a C++ program - simply you should carefully encapsulate it in an utility class, in order to preserve the OO high level structures.

提交回复
热议问题