代码

#include "pch.h"
#include "Shudu.h"
//判断字符串是否只有数
using namespace std;
bool isnum(string s)
{
    stringstream sin(s);
    double d;
    char c;
    if (!(sin >> d))
        return false;
    if (sin >> c)
        return false;
    else
        return true;
}
int main(int argc, char** argv)
{

    int n;
    ofstream out("sudotiku.txt");
    //判断输入是否合法
    if (argc == 3)
    {
        if (strcmp(argv[1], "-c") == 0) //-c:生成的数独棋盘的数量
        {
            if (!isnum(argv[2]))
            {
                cout << "Error input parameter" << endl << "Please re-enter an integer:";
                cin >> n;
            }
            else
            {
                n = atoi(argv[2]);
            }
        }
        else
        {
            cout << "Error input parameter" << endl << "Please re-enter an integer:";
            cin >> n;
        }
    }
    else
    {
        cout << "Error input parameter" << endl << "Please re-enter an integer:";
        cin >> n;
    }
    //判断输入的数字是否为0
    while (n == 0)
    {
        cout << "Error input parameter" << endl << "Please re-enter an integer:";
        cin >> n;
    }
    Shudu *sd = new Shudu[n];//动态生成n个数独
    srand(unsigned(time(NULL)));//产生随机数种子,防止每次产生的随机数相同
    for (int i = 0; i < n; i++)
    {
        sd[i].GenerateShudu();
        sd[i].PrintShudu();
        sd[i].WriteFile(out);
        cout << endl;
        out << endl;
    }
    delete[] sd;
    return 0;
}
原文地址:https://www.cnblogs.com/xiaoyoushang/p/9790467.html