#include <iostream>using namespace std;int main() {char str[5] = {'1', '2', '3', '4', '\0'};int num = 0;int i = 0;while(str[i]) {num = num * 10 + (str[i++] - '0');}cout << num << endl;return 0;} // 字符串转正整数
#include <iostream>using namespace std;int main() {// 整数转字符串int num = 1234;char temp[7], str[7];int i = 0, j = 0;while(num) {// 整数转字符串: +'0'temp[i++] = num % 10 + '0';num = num / 10;}// 刚刚转化的字符串是逆序的while(i >= 0) {str[j++] = temp[--i];}cout << str << endl;return 0;}
