I’m learning C++, and I’m doing work with data loaded from external text files using cin.
I’m trying to recognize certain strings in large amounts of data that I need to skip through.
How would I write a function that skips through a certain number of characters in a file / on a line, either as I’m importing them from a file? Does such a thing already exist in iostream or similar?
Google has let me down so far.
On general skipping: seekg
On the real issue:
It seems like you would want to be matching patterns against a large body of (semi?) text. Since the pattern is long enough that you can gain from skipping input stretches, it really seems you are trying to invent optimized string search all over.
It has been done:
Implementations exist in the wild (I assume Boost String Algorithm should have it… but maybe it too general-purpose to have it. I’d have a look anyways)
PS.: Boost Spirit
This parser is currently reviewing an enhancement that implements the
qi::seek[]directive:This allows blazingly fast skipping inside a Spirit grammar. So if you have a case for a full parser (perhaps even scanner/parser), Spirit Qi could really be your match in performance.
Be sure to: