What is a good way to convert character array of varying sizes to a string? (C++)
Story: Hello, I tried to create a function in C++ that converts a character's integer value to a string, for example f('x') -> "120" and f('4') -> "52". I prefer modifying the string as an array of characters inside the function and then convert it to string before returning it, but... Actual problem: I somehow end up getting garbage values. The problem seems to caused by the conversion. I think it happens, because the char array-to-string conversion doesn't know the size of the character array, which can vary between 1, 2 and 3, making string assume the character array has 3 characters causing extra characters to be replaced with garbage values. I've tried to using string.resize function to cut off the garbage values, but I have a feeling it's not a good way. Questions: What are good ways to convert character array of varying sizes to a string? Is cutting garbage values off the string using string.resize function a good way to fix the problem? Is there a way to initialize a string with a specified length? Here is the code: https://code.sololearn.com/clHWHfZs5flZ