Timeline for How do I tokenize a string in C++?
Current License: CC BY-SA 2.5
17 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 3, 2022 at 6:33 | comment | added | Emanuel P | This shows the beauty of c++. You need 8 include files, 5 different types, and best of all... nowhere in the code is it actually readable that all it's doing is splitting a string on whitespace. Without knowledge of the specific behavior of these STL classes this is completely unintelligible. | |
Aug 12, 2017 at 23:03 | comment | added | Nubcake |
@Miek Especially when using Boost and the standard library (<regex> ) which can be boost::regex or std::regex
|
|
Feb 8, 2016 at 22:40 | comment | added | user325117 |
You don't need to #include <istream> or <ostream> .
|
|
Nov 6, 2015 at 4:51 | comment | added | YePhIcK |
Could you update your answer for std::wstring s? I seem to be too dumb to make it compile :(
|
|
Apr 15, 2015 at 11:08 | comment | added | Skizz | This is very clever but how could I split the string by, say, a comma rather than a space or is whitespace the only separator - I ask because my quick search online about how this works failed to mention how strings are split. | |
Nov 20, 2013 at 16:19 | review | Suggested edits | |||
Nov 20, 2013 at 16:23 | |||||
Jul 18, 2012 at 17:08 | comment | added | Miek | yep! what he said! best practices is to use the std prefix. Any large code base is no doubt going to have it's own libraries and namespaces and using "using namespace std" will give you headaches when you start causing namespace conflicts. | |
Apr 11, 2012 at 14:54 | comment | added | dlchambers | Despite the "std::" prefixes being irritating or ugly, it's best to include them in example code so that it's completely clear where these functions are coming from. If they bother you, it's trivial to replace them with a "using" after you steal the example and claim it as your own. | |
Mar 20, 2012 at 18:12 | review | Suggested edits | |||
Mar 20, 2012 at 18:17 | |||||
Jan 31, 2012 at 0:42 | comment | added | Good Person | user - because someone may copy this example and we wouldn't want them to use 'using' :) | |
Dec 30, 2011 at 15:40 | review | Suggested edits | |||
Dec 30, 2011 at 16:43 | |||||
Oct 16, 2011 at 14:33 | comment | added | Arnthor | Honestly, in function way this would be much more usable. And those std:: are simply ugly. I did an edit, but I don't expect it to show up somewhere in near future. Nevertheless, I'll try it out. | |
Oct 16, 2011 at 14:28 | review | Suggested edits | |||
Oct 16, 2011 at 15:16 | |||||
Jul 16, 2010 at 11:27 | comment | added | cheshirekow | I understand your reason and I think it's actually a good choice if it works for you, but from a pedagogical standpoint I actually agree with pheze. It's easier to read and understand a completely foreign example like this one with a "using namespace std" at the top because it requires less effort to interpret the following lines... especially in this case because everything is from the standard library. You can make it easy to read and obvious where the objects come from by a series of "using std::string;" etc. Especially since the function is so short. | |
Apr 2, 2010 at 8:49 | comment | added | Matthieu M. |
@Vadi: because editing someone else's post is quite intrusive. @pheze: I prefer to let the std this way I know where my object comes from, that's merely a matter of style.
|
|
Nov 28, 2008 at 4:19 | comment | added | user35978 | I find those std:: irritating to read.. why not use "using" ? | |
Sep 10, 2008 at 12:46 | history | answered | KeithB | CC BY-SA 2.5 |