The ascii value of a char variable can be known using the int() function.
Is there a way to do the same for each character of a string datatype?
For eg. string var=starwars;
How can I print the ascii values of all the characters of string variable ‘starwars’ using some cpp functionality?
for (int x : var) { …
And you are 2 days too late for a star wars reference 
I’m sorry, I don’t get it. Could you please elaborate?
I’m not sure if you read the problem right, or maybe it’s just that I don’t understand the solution! So if you could give it another shot.
And for the star wars reference, it’s still on my mind even though it’s been 2 days.
MAY THE FORCE BE WITH YOU! 
I didn’t know your exact print format so I let it to you. But this should work:
string var = "starwars";
for (int x : var) {
cout << x << endl;
}
1 Like
Alright, I got it.
Thanks a lot! 