Thus the first argument to writeFile should be either char const* or std::string const&. This does not mesh well with string_view, because string_view does not guarantee NUL-termination. Unfortunately, std::ofstream interface is antique: it still expects a C-String as an argument. writeFile does not need to take a copy of a string.hexify does not need to take a vector, any sequence of unsigned char would work.Your functions arguments are over-constrained, compared to what is actually necessary: Generally speaking when you're using iterators in a loop, since end() is past the last element, it's better to use not equals( !=) instead of less than.ĭisclaimer: if you want to use std::ostream and its manipulators, see answer. When you have a need for literal (magic) use a constant variable. If reinventing the wheel is the point, first there's a tag for that. Std::string hexify(std::vector const & v) Std::ofstream f(str.data(), std::ios::binary) To write the vector to a file as base 16 numbers, you can do that directly in the writeFile function: void writeFile(std::string_view str, std::vector const & v) It seems like you're trying to reinvent the wheel here. I would suggest looking at your IDE's menu options and use the format command. First off, your formatting is not very good.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |