#include <iostream>
using namespace std;
typedef struct version
{
int firstClassVersion;
int secoidClassVersion;
int thirdClassVersion;
} Version;
Version operator++(Version &ver)
{
if (ver.firstClassVersion > 99)
{
Version wrongVersion = Version{0, 0, 0};
cout << "版本号用完了"<< endl;
return wrongVersion;
}
Version tmp;
if (ver.thirdClassVersion + 1 > 99)
{
ver.thirdClassVersion = ver.thirdClassVersion - 99;
ver.secoidClassVersion++;
if (ver.secoidClassVersion > 99)
{
ver.secoidClassVersion = ver.secoidClassVersion - 99;
ver.firstClassVersion++;
}
}
else
{
ver.thirdClassVersion = ver.thirdClassVersion + 1;
}
tmp.firstClassVersion = ver.firstClassVersion;
tmp.secoidClassVersion = ver.secoidClassVersion;
tmp.thirdClassVersion = ver.thirdClassVersion;
return tmp;
}
void getStringVersion(Version& ver,string& strVer)
{
strVer = "v:" + std::to_string(ver.firstClassVersion) + "." + std::to_string(ver.secoidClassVersion) + "." + std::to_string(ver.thirdClassVersion) ;
cout << strVer << endl;
}
void printVersion(Version &ver,int num)
{
cout << "ver[ " << ver.firstClassVersion << "." << ver.secoidClassVersion << "." << ver.thirdClassVersion << "]"<<",num = "<<num << endl;
}
int main()
{
Version curVer = Version{3, 0, 0};
string strVer;
printVersion(curVer,0);
for (int i = 1; i < 1000000; i++)
{
++curVer;
if(curVer.firstClassVersion == 100&&curVer.secoidClassVersion == 1&& curVer.thirdClassVersion==0 )
{
cout << "版本号已经用尽,需检查"<<endl;
exit(1);
}
//printVersion(curVer,i);
getStringVersion(curVer,strVer);
}
}
玩具版本~~
最新推荐文章于 2024-11-06 20:28:22 发布