I'm rewriting a program in C++ to see if i can improve the speed, and i need to convert a char[] to int[] with the character values as in Java, as you can see, i write this code in Java:
public static void main(String[] args) {
System.out.println("Insert text:");
Scanner D = new Scanner(System.in);
String text = D.nextLine();
int[] textInt = StringToIntArray(text);
printArray(textInt);
}
public static int charNum(char x){
int a = x;
return a;
}
public static int[] StringToIntArray(String text){
int[] result = new int[text.length()];
for (int i = 0; i < result.length; i++) {
result[i] = charNum(text.charAt(i));
}
return result;
}
public static void printArray(int[] x){
for(int i : x){
System.out.print("["+i+"] ");
}
System.out.println("");
}
(If you input Hello it will print [72] [101] [108] [108] [111])
But i just get noticed that in c++ the default char format is ANSI and someone tell me that Java uses UTF-16. I just need to convert text even from char[] or std::string to an int[] but i really need the same values