I have the next C++ code snippet:
...
static constexpr const char* my_char_array [10] { // Some literals here... } // Member of a class
std::vector<std::string> splitted_input { // Contains C++ strings }
std::vector<std::string> matched_keywords { // The coincident ones will be copied here }
for (int i = 0; i < sizeof(this->my_char_array); i++) {
std::cout << "Comparing: " << this->my_char*_array[i] << std::endl;
auto value = std::find(splitted_input.begin(), splitted_input.end(), (std::string) this->my_char_array[i]);
if ( value != end(splitted_input) ) {
matched_keywords.push_back(this->keywords[i]);
}
}
I am iterating over an const char*, looking for a literal that could be inside a vec<string>.
When I use the std::find algorithm, the for loop stops on the first iteration (std::cout just outputs the first value on my_char*_array).
Never faced an issue like that. Any idea?
Thanks in advice.
my_char*_array? That's not a valid name. Please create a proper minimal reproducible example to show us.sizeofoperator will return the size of the object in bytes. For an array it will only return the number of elements if the array is an array ofchar(notchar*but plainchar).sizeof(this->my_char_array)/sizeof(this->my_char_array[0]), to get size ofmy_char_arrayarraystatic constexpr std::array<const char*, 2> my_char_array = {"dsds", "dddd"};andmy_char_array.size()