在c ++

时间:2016-04-26 18:41:25

标签: c++

我想为我的患者班生成一个唯一的ID,所以我提到了问题

Auto generate ID in C++

以下课程

class patient {

    int id;

    static int current_id;

    patient() : id(current_id++) {}
};

int patient::current_id;

每次执行程序时,它都会从1生成'current_id'到'n'。 这里n = 1,2,3,4 .....

我想要唯一地生成'current_id',即使我执行程序任何时候都应该是唯一的。

我正在做一个c ++项目来存储客户和产品信息,我想把它存储在一个文件中。

class Customer
{
    int id;
    string name;
    string type;
    unsigned long long int PHNO;
    string street,city;
    unsigned int PIN;
public:
    Customer(){}
    friend void readdata();
};
class Product
{
    int pid;
    string pname,ptype;
    unsigned int price;
    string brand_name,suitable_for;
public:
    Product(){}
    friend void readdata();
};

这里我不会将'id'或'pid'作为输入,但是我想自动生成它然后它应该存储在一个文件中。

我也提到了

How can I create a guid in MFC

但我不知道如何在上课中使用。

有没有办法生成独特的'current_id'?

如果有人知道答案后适当的或修改过的课程。

0 个答案:

没有答案
相关问题