I'm taking an intro C++ class, the only thing I have experience with is Java (only thing offered and my self-teaching has been with irrelevant things such as lisp) and have a quick question.
I'm trying to break the lines of a text file into separate strings to be input into a struct, using a colon as the token. I have no idea how to go about this in C++ though, can someone shed some light here?
I don't need nor want for someone to write my program for me, I'm just not sure how to segregate the lines into distinct strings.
Name:
Anonymous2012-07-22 11:55
An example line looking something like:
Sleepyhead : Passion Pit :Manner
In this scenario, I'm trying to get three strings: "Sleepyhead", "Passion Pit", "Manner".
>>5
There's strtok_r in GNU C if you need to split strings at same time in several threads.
Which you don't in most circumstances, and if you really do, can't use GNU C and aren't willing to use/write alternative functions, can always get around with mutexes.
>>10
Yes, you would have to do that, but that shouldn't be very long and it would be unnoticable (unless that's the main function of your program and it does it all the time on huge amounts of data, in which case go write your own version of that function).
>>11
Which scenario do you expect you would have to use strtok from multiple threads yet not needing performance? If you look out every other thread for the duration of tokenization then you basically have a single threaded program.
Name:
Anonymous2012-07-23 23:50
` >being a professional codemonkey
>2012 LOL!
Signed,
A Professional Engineer
>>14
I can't really imagine a realistic scenario where you'd need to use strtok in multiple threads at once for performance. If you're using it in several threads, then it's likely something like an event-driven program whose main purpose isn't string tokenization.