0

I have a file(as text) from which I should extract all included files names. The implementation should be in C++ What I thought to do is to read a file line after line (getline) check if line starts from #include - how do I do that?(there could be leading spaces) and after that extract the file name - the string which is between " " - how do I do that? Thanks

YAKOVM
  • 9,805
  • 31
  • 116
  • 217

1 Answers1

0

First of all an include may be placed either between <> or between "" so you have to check for both.

Next - best way to do what you try is using regular expressions. If you are using c++11 they will be part of the standard and you should be good to go. If that is not the case maybe try boost::regex for instance.

If using regular expressions is not an option you will have to implement your own parsing but this will be error-prone and most probably you will miss some freaky edge-case. If I have to I would implement such parsing by going over the file line by line. Than I would check if the line contains #include as substring and verify there are only whitespaces before it. If the line does have the mentioned substring I would than iterate over the remaining part of the line to parse the part between <> or "".

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176