One problem here is that you're assuming your computer is using an ASCII-compatible encoding. This is not guaranteed to be the case.
In the style of a canonical Unix filter program, try something like this:
1 2 3 4 5 6 7 8 9 10 11
# include <algorithm>
# include <iostream>
# include <iterator>
# include <locale>
int main() {
std::cin.imbue(std::locale("C"));
using it = std::istream_iterator<char>;
std::for_each(it{std::cin}, it{}, [](auto c){
std::cout << std::hex << static_cast<int>(c) << '\n'; });
}