zoukankan      html  css  js  c++  java
  • 返回值--CString和指针的区别

    CString 对string进行了重新的封装处理

    char *ReadLob(CString filename)

    {

      char msgbody[1024];

      return msgbody

    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////<区别

    int ReadLob(CString filename, char* node702_msgbody, int iSz)

      std::ifstream file;  file.open(filename); 

      if(!file)

       {   printf("Unable to open file ");   return -1;  }

       char pBuf[1024*4];  int iRead = 0, iCur = 0;

      while(!file.eof())    

      {       

          file.read(pBuf,sizeof(pBuf));      

           iRead = file.gcount();            

          int iCpy = iRead+iCur >= iSz ? iSz - iCur - 1 : iRead;       

          strncpy(node702_msgbody+iCur, pBuf, iCpy);       iCur += iCpy;      

           if(iCur == sizeof(node702_msgbody) - 1)            

              break;    

       }    

      node702_msgbody[iCur] = 0;   

       return 0;

    }

    ///////////////////////////

    说是第一种,指针必须是new的才可以作为返回值,不让函数内的数组头,作为指针返回,会出现问题,

    我操作之所以没有出现问题是因为,中没有别的代码来破坏之前的栈空间

    可以返回CString的类型,CString可以保护起来字符串。

    最好还是第二种方式

    ///////////////////////////

    读取字段要加入iCur来分段读取,这样会好些

  • 相关阅读:
    jQuery
    jQuery
    jQuery Callback 函数
    怎样提高团队管理能力4
    poj 3461 Oulipo(KMP模板题)
    每日一小练——按字典顺序列出全部排列
    Java数据结构与算法之排序
    China Vis 2015 会议小结
    网络基础知识小小说
    NS3网络仿真(7): Wifi节点
  • 原文地址:https://www.cnblogs.com/orchid-sky/p/3528524.html
Copyright © 2011-2022 走看看