C++ String parsing

Shadowssong

[H]ard|Gawd
Joined
Sep 17, 2009
Messages
1,969
Hey guys I'm working on my final project for my data structures class and we are creating a hash table ADT and then implementing a simple password server with it. One of the functions I have to write for the hash table is to read from a file and the inputs will be in this format:

username:encrypted_password

In which I need to seperate the two, as they are stored in a pair(of strings) in my seperately chained hash table.

I have used stringstream before to parse based on spaces and it works well but I don't know how to parse it based on the ":"... Any ideas? I have the rest of the code written for the rest of it I just don't know how to parse it into two strings. I can use any library, but I have the feeling the stringstream can do this but I can't find any documentation supporting this idea.

Any help would be greatly appreciated!
-Greg

PS: Also for extra credit on this assignment I am allow to make a GUI for the program and I have done 0 gui programming (unless you count VB way back in the day) and my friend suggested QT creator and I have installed it (I'm running Ubuntu) and I'm looking for just a basic tutorial, also something I can't find (I guess I suck at google lol). I'd need maybe 6 or 7 buttons, a few input boxes and a few output boxes, so nothing complicated, just not sure where to start, atleast when it comes to making the interface in QT. I don't need the extra credit but I really want to make something useful and have a bit of fun with the GUI.
 
Why can't you just loop over it and find the ":" yourself?

Anyway, stringstream inherits istream::getline() which optionally takes a delimiter as its third argument.
 
Thanks, I forgot that getline takes a delim haha. Sometimes I overlook the simple things, thanks man.
 
Last edited:
Back
Top