I am trying to cast the value of a char(not the ASCII address) to size_t. I have succeeded but it feels like a lot of steps for something that seems to be straight forward (coming from C# background).
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
int main() {
std::vector<size_t> singleDigits { 1, 4, 6, 8, 9 };
std::string content = "1234";
for (size_t j = 0; j < content.length(); j++) {
std::string stringValue = std::string(1, content[j]);
auto iterator = std::find(singleDigits.begin(), singleDigits.end(), (size_t)std::stoi(stringValue));
if (iterator == singleDigits.end()) {
std::cout << "Not found" << std::endl;
} else {
std::cout << stringValue << " was found" << std::endl;
}
}
}
So currently I am casting the char to string, cast the string to int and then cast the int to size_t. I am sure I am missing something obvious?
So my question is: What is the proper way to cast the char to size_t for the example above?