My high level goal is to convert any string (can include non-ascii characters) into a vector of integers by converting each character to integer.
I already have a python code snippet for this purpose:
bytes = list(text.encode())
Now I want to have a C++ equivalent. I tried something like
int main() {
char const* bytes = inputText.c_str();
long bytesLen = strlen(bytes);
auto vec = std::vector<long>(bytes, bytes + bytesLen);
for (auto number : vec) {
cout << number << endl;
}
return 0;
}
For an input string like "testΔ", the python code outputs [116, 101, 115, 116, 206, 148].
However C++ code outputs [116, 101, 115, 116, -50, -108].
How should I change the C++ code to make them consistent?
char*you'll likely want to use wide characters and unicode literals stackoverflow.com/questions/6796157/… for example Python'sstr.encodeuses utf-8 by default, so here's an explanation of utf-8 support in C++ stackoverflow.com/questions/50403342/…