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来分段读取,这样会好些

  • 相关阅读:
    IO流(5)—缓冲流
    vue-element-admin 中文问题
    npm 下载慢解决方案
    fatal: unable to connect to github.com
    为什么有sessionStorage,localStorage等,还需要vuex
    vuex页面刷新数据丢失的解决办法
    Node中JWT的使用
    socket.io 实现长连接演示代码
    WebSocket 实现长连接演示代码
    jquery ajax上传文件
  • 原文地址:https://www.cnblogs.com/orchid-sky/p/3528524.html
Copyright © 2011-2022 走看看