#include#include using namespace std; int main() { string str = "42"; int num = stoi(str); cout << "The integer value of the string is: " << num << endl; return 0; }
#includeIn this example, we use a character array `arr` to store the value "123". We then use the `stoi` function to convert this character array to an integer value, which we store in the variable `num`. Finally, we print out the value of `num` to the console. This code makes use of the `std` package library.#include using namespace std; int main() { char arr[] = "123"; int num = stoi(arr); cout << "The integer value of the character array is: " << num << endl; return 0; }