+ 3

String split

I need a c++ function that splits each word in a string into a vector. using getline(cin,str) So if the user inputs "Hello World!" the vector should contain either (Hello,World!) or (Hello, World) depending on how you want to do it, it doesn't matter to me. I got it to work with arrays, but not vectors.

20th Feb 2019, 9:01 PM
Daniel Cooper
Daniel Cooper - avatar
11 Réponses
+ 6
Daniel, why you expect two versions of outputs ("Hello", World!") and ("Hello", "World"). If you want to exclude anything other than alphanumeric then that is more than just splitting a string, as there is character filter implementation involved. I just need a bit clarification of your actual intention 👍
21st Feb 2019, 10:46 AM
Ipang
+ 5
Daniel Cooper It's quite alright, but my doubt stands still, do you want the splitter to choose to ignore punctuation or other characters, as I see you expected two different outputs from the splitter, one with exclamation mark, and one without.
21st Feb 2019, 5:08 PM
Ipang
+ 5
Daniel Cooper Can you post the link to the code you're working on so I have a basic understanding where this is going? I think I might be able to help a bit. You mentioned Discord, you mean in SoloLearn Discord server or that of another server you joined?
22nd Feb 2019, 3:39 AM
Ipang
+ 4
Good job Daniel Cooper 👍 Is that Discord server good or what? I'm interested if it is good.
22nd Feb 2019, 6:14 AM
Ipang
+ 3
Ipang HonFu Sorry guys. I didn't think I'd get a reply on my original thread and I got too impatient. Thanks for your answer HonFu! I'll make sure to stick to the same thread next time. 😊
21st Feb 2019, 5:02 PM
Daniel Cooper
Daniel Cooper - avatar
+ 2
I've also seen you post quite a few variations of basically the same question, but you rarely even comment a given answer. So instead of making post after post, it would help if you stuck to one thread and, as Ipang said, communicate a bit more!
21st Feb 2019, 10:51 AM
HonFu
HonFu - avatar
+ 2
It was really a choice for the answerer if they wanted to include special chars or not. Lol I can probably figure it out myself, but I included the output without the special chars in case the person answering wanted to do it that way. Sorry for the confusion guys. Was in a hurry to get it figured out before work so I could reply to the discord user who needed it. Next time I'll just ask one question or just put more effort into solving it myself. Lol
21st Feb 2019, 8:33 PM
Daniel Cooper
Daniel Cooper - avatar
+ 2
Ok, apparently I can't figure out the filter. Any tips?
22nd Feb 2019, 1:11 AM
Daniel Cooper
Daniel Cooper - avatar
+ 2
https://code.sololearn.com/c7Nxs4x2HWnF/#cpp I figured out the filter. I was looking at the problem backwards. Lol All I need now is to make the word check ignore caps. Edit: I found out how to ignore caps. And it's not the Sololearn server. DIfferent server. Edit Again: Here's the finished code: https://code.sololearn.com/cQw8SYY0V944/#cpp Thanks to anyone who helped
22nd Feb 2019, 4:41 AM
Daniel Cooper
Daniel Cooper - avatar
+ 2
Pretty good. It's a homework help server. Literally called Homework Help. You can find it on discord.me I think.
22nd Feb 2019, 6:25 AM
Daniel Cooper
Daniel Cooper - avatar