dimanche 25 janvier 2015

Parsing C++ strings

There are lots of posts here about posting strings but non actually seems to fit to my purpose.


I'm using std::string and all of C++ standard libraries, and I have a text file using the following protocol:



TEXT1:TEXT2-TAB-TEXT3:TEXT4 TEXT5


When -TAB- is \t.


I want to get all the text into strings (could be an array too). All of the lines in the file are written this way, I tried using istringstream but it has no functionality such as: iss >> text1 >> ":" >> text2 >> "\t" >> text3 >> ":" >> text4 >> " " >> text5.


Do I actually need to parse using the basic functions of find etc. ? That'd be just a ton of work (because I have a couple of files written in different formats and I'll need to make a general function for all of these), I would do that if I have no choice though.


So... is there any way to parse strings the following ways, using known characters between strings? It's not a specific delimiter because each line contains a couple delimiters (one time it's space, then a colon and so). I want to use C++ standard libraries and not any external library such as Boost.


EDIT: C++11.


Aucun commentaire:

Enregistrer un commentaire