3 ms·
I wrote a clean C++ version of `wc` for fun, and successfully beat the system version by 10-20% iirc. My goal was to make the code much more readable than the G
by Maro 2y ago
I wrote a clean C++ version of `wc` for fun, and successfully beat the system version by 10-20% iirc. My goal was to make the code much more readable than the GNU/C version, which is a big spaghetti loop, while maintaining the same semantics (ie. return the same counts).
Blog posts:
https://bytepawn.com/tag/wc.html https://bytepawn.com/tag/wc.html
Code:
https://github.com/mtrencseni/wcpp/ https://github.com/mtrencseni/wcpp/
- butterisgood 2y agoA "word" counter in C++ (not really, but kind of) std::cout << std::distance(std::istream_iterator<std::string>(std::cin), std::istream_iterator<std:::string>()) << std::endl; And I guess you could get "character" count using istreambuf_iterator. Don't do this :-) (Though I've used it in a pinch)
- butterisgood 2y agoAlso, sorry for the typos... the character version is istreambuf_iterator<char> also... whoops!