我讲一个点类成员存入一个txt出现了这样的问题。代码如下:
buffer.Format("%s%d",buffer,p[i].x);
file.Write(buffer,sizeof(p[i].x));
buffer.Empty();buffer.Format("%s%d",buffer,p[i].y); file.Write(buffer,sizeof(p[i].y)); buffer.Empty();奇怪的是,保存在文本里是
     "屯100 237 "
这一类的东西,但实际上p[i]里的是1,1而当我改成
buffer.Format("%s%d",,p[i].x);
时,却会出现内存溢出的错误。向高手求救~

解决方案 »

  1.   

    buffer.Format("%s%d",buffer,p[i].x);
    file.Write(buffer,buffer.GetLength());
    buffer.Empty();buffer.Format("%s%d",buffer,p[i].y);
    file.Write(buffer,buffer.GetLength());
    buffer.Empty();p[i].x,p[i].y是什么数据类型啊?
      

  2.   

    为什么你总是用一些不正常的操作呢,一个字符串把自己和另外的东西放在一块??还用format?你不能用别的方法吗?
    strcpy,memcpy好多呀
      

  3.   

    p[i]是int型的.strcpy我也用过,原buffer是char *型但运行时也会出现内存出错的问题,所以就改用cstring然后format来试了。能告诉我如果用strcpy应该怎么编么?
      

  4.   

    按楼上的方法保存后是
    〱0ㄳ2但实际上我存入的是
    p[i].x=1
    p[y].y=1
      

  5.   

    ResThe call will fail if the string object itself is offered as a parameter to Format. For example, the following code:CString str = "Some Data";
    str.Format(_T("%s%d"), str, 123) );   // Attention: str is also used in the parameter list.causes unpredictable results.
    你的buffer.Format("%s%d",buffer,p[i].x); 不行吧
      

  6.   


    CString str;
    str.Format("%s%d",buffer,p[i].x);看看如何
      

  7.   

    CString strTemp;
    strTemp.Format(_T("%s"), p[i].x);
    buffer += strTemp;
    file.Write(buffer,sizeof(p[i].x));
    buffer.Empty();
      

  8.   

    你的FILE是CFILE吗?
    为什么不调试跟踪看是FORMAT出错还是WRITE呢
    CString buffer ;
    buffer.Format("%d", p[i].x);
    file.Write(buffer.GetBuffer(buffer.GetLength()),buffer.GetLength());
    buffer.Empty();