class CMontew
{
public:
char namew[5];
float para1;
float para2;
float randf1;
int value;

int symbol;
};
我定义了上面的一个类,vctor里成员都是这种结构,当我要改变成员中value的值时,改变不了,value一直都为0;但我当把类的int value改为 float value时,就可以了,这是为什么啊????

解决方案 »

  1.   

    void CAddEvents::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    //UpdateData();
    CString str3,str4; int m=0;
    int j=m+1; double randf;
    srand(GetTickCount());
    randf=(double)(rand()/(double)RAND_MAX);
    vector<CMontew>::iterator i,iend;
    iend=lm1.end();
    for(i=lm1.begin(); i!=iend; i++)
    {
    switch ((*i).symbol) //判断事件类型
    {
    case 0:
    {(*i).randf1=(*i).para1+(*i).para2*randf; //计算时间
    }
    break;
    case 1:
    {(*i).randf1=-(*i).para1* log(randf);
    }
    break;
    case 2:
    {(*i).randf1=(*i).para1*pow(-log(randf),(*i).para2);
    }
    break;

    } (*i).value=1;
    s[m].randf1=(*i).randf1;
    m++; }

    std::sort(lm1.begin(), lm1.end(), comp);
    for(i=lm1.begin(); i!=iend; i++)
    {
    str3.Format("%5.0f ",(*i).value);
    str4+=str3;
    GetDlgItem(IDC_EDIT2)->SetWindowText(str4);
    }}
    这是其中对value设值的代码
      

  2.   

    (*i).value=1; //改变其中的vlaue值这里我只是想看一下能不改。
    是不是我其中的
    ("%5.0f "
    的原因??
      

  3.   

    知道了,是这个原因。改成"%5d"就好了。呵呵,
    对了,我设定value是bool型的,应该以什么形式输出啊??也就是二进制的输出格式是什么啊??
      

  4.   

    bool类型不支持的,楼主直接打印整型好了,当然,考虑到大小,楼主可以打印%c:
    str3.Format("%c ",(*i).value ? '1':'0');反正按楼主实际情况来,还有楼主(("%5.0f ),你设置int,不是没值,而是格式化的时候没格出来 。