字符串转化为数字 不用sscanf
#include <iostream> #include <string.h> using namespace std; int main() { int tmp; int num = 0; char s[] = "123"; for (int i = 0; i < strlen(s); i++) { tmp = s[i] - '0'; num = num * 10 + tmp; } cout << num; }
#include <iostream> #include <string.h> using namespace std; int main() { int tmp; int num = 0; char s[] = "123"; for (int i = 0; i < strlen(s); i++) { tmp = s[i] - '0'; num = num * 10 + tmp; } cout << num; }