How do I iterate over the words of a string?

I use this to split string by a delimiter. The first puts the results in a pre-constructed vector, the second returns a new vector. #include <string> #include <sstream> #include <vector> #include <iterator> template <typename Out> void split(const std::string &s, char delim, Out result) { std::istringstream iss(s); std::string item; while (std::getline(iss, item, delim)) { *result++ = … Read more

How do I cast int to enum in C#?

From an int: YourEnum foo = (YourEnum)yourInt; From a string: YourEnum foo = (YourEnum) Enum.Parse(typeof(YourEnum), yourString); // The foo.ToString().Contains(“,”) check is necessary for // enumerations marked with a [Flags] attribute. if (!Enum.IsDefined(typeof(YourEnum), foo) && !foo.ToString().Contains(“,”)) { throw new InvalidOperationException( $”{yourString} is not an underlying value of the YourEnum enumeration.” ); } From a number: YourEnum … Read more