Is there an equivalent in C++ of PHP’s explode() function? [duplicate]

Here’s a simple example implementation: #include <string> #include <vector> #include <sstream> #include <utility> std::vector<std::string> explode(std::string const & s, char delim) { std::vector<std::string> result; std::istringstream iss(s); for (std::string token; std::getline(iss, token, delim); ) { result.push_back(std::move(token)); } return result; } Usage: auto v = explode(“hello world foo bar”, ‘ ‘); Note: @Jerry’s idea of writing to an … Read more

What is the equivalent of memset in C#?

You could use Enumerable.Repeat: byte[] a = Enumerable.Repeat((byte)10, 100).ToArray(); The first parameter is the element you want repeated, and the second parameter is the number of times to repeat it. This is OK for small arrays but you should use the looping method if you are dealing with very large arrays and performance is a … Read more