#include <iostream>
#include <sstream>
#include <windows.h>
using namespace std;
int getNum(string str)
{
int a;
stringstream ss;
ss << str;
ss >> a;
return a;
}
int main()
{
//sizeof(arr) / sizeof(arr[0]);
//48-57
SetConsoleTitle("C++数字转换练习");
cout << "欢迎来到C++数字转换练习程序!作者纯属小白!" << endl;
cout << "请输入您的数字:";
string timeStr;
cin >> timeStr;
const int len = (int)timeStr.size();
int allLS[len];
bool notAllNum = false;
for (int i = 0; i < len; i++)
{
allLS[i] = (int)timeStr[i];
}
for (int i = 0; i < len; i++)
{
if (!(allLS[i] >= 48 && allLS[i] <= 57))
{
notAllNum = true;
break;
}
}
if (notAllNum)
{
cout << "您的输入方法不合理!程序自动退出!" << endl;
system("pause");
}
else
{
string numStr;
for (int i = 0; i < len; i++)
{
numStr += (char)allLS[i];
}
int num = getNum(numStr);
cout << "成功获取数字!" << endl;
system("pause");
}
return 0;
}