lol I can get it down to 3 lines inside a function, but no one liner :(. Perhaps 2
Printable View
lol I can get it down to 3 lines inside a function, but no one liner :(. Perhaps 2
I should've said "a single line of statement" instead of just saying a single line.
My one liner spans across the screen little too much
So I'm sure your 2 lines is as good as mine, if not better. :)
lol here is my code ;)
and this is how you use itCode:void Tokenize( const string& TokenString, vector< string >& Tokens, char Delimiter = '$' )
{
string Token;
stringstream TokenSplitter( TokenString );
while( getline( TokenSplitter, Token, Delimiter ) ) Tokens.push_back( Token );
}
I think that is 3 statements :rolleyes: enjoyCode:vector<string> Tokens;
Tokenize( "1 2$3$4\n5$6", Tokens );
That's great :)
Mine can be used if there's no luxury of affording 3 statements :p
and can be used with a similar function call as yoursCode:void Chunkify(const string& s, vector<string>& v, unsigned int p = 0, char delim = '$')
{
return string::npos != (p = s.find(delim)) ? v.push_back(s.substr(0, p)), Chunkify(s.substr(p + 1), v, p) : v.push_back(s);
}
But as I said before, I'm sure yours is better :)Code:vector<string> Tokens;
Chunkify( "1 2$3$4\n5$6", Tokens );
lol nice one :) That is some way of doing it
I suppose you can take out that return keyword in your function?
Four, depending on your point of view. But you probably should have let farooq124in try it first.Quote:
Originally Posted by Joeman
I am not complaining since farooq124in did try enough and it is only so little of code. It isn't 100 lines of unique code :)
You will notice I didn't include headers for a reason
Heheh :)Quote:
Originally Posted by Joeman