How trans file path from vb to MFC static dll

本文介绍了一个使用C++进行字符串分割的方法,并演示了如何从文件中读取数据并解析为数值型数据。此外,还提供了一个将任意类型转换为字符串的通用函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

void split(const CString str,const CString bystr,CString *str_array)
{
int nLen = bystr.GetLength();
int preLoc = 0;
int nowLoc = 0;
int i=0;
while(true)
{
   nowLoc = str.Find(bystr,preLoc);
   if(nowLoc == -1&&preLoc == 0)
   {
    CString substr3=str;
    *(str_array+i)=substr3;
    i++;
    break;
   }
   if(nowLoc == -1&&preLoc != 0)
   {
    CString substr2=str.Mid(preLoc);
      *(str_array+i)=substr2;
    i++;
    break;
   }
   CString substr = str.Mid(preLoc,nowLoc-preLoc);
   *(str_array+i)=substr;
   i++;
   preLoc=nowLoc + nLen;
}
}

template <class T> 
std::string ConvertToString(T value) 
{
std::ostringstream ss_liu;
    ss_liu<<value;
    return ss_liu.str();
}

void _stdcall selpoint(char* path,double* xx,double* yy,double* zz,int* kk)
{
    CString FileIN;
    CStdioFile FileInName;
CFileException e;
int i=0;
int position=0;
    CString tmp_arr[8];
    double tvx;
    double tvy;
    double tvz;

    
    FileIN=path;
    FileInName.Open(FileIN,CFile::modeRead,&e);//Open FileIN For Input As #FileInName
        
    while(total_num>0)
{    
    FileInName.ReadString(valstr);
       split(valstr,",",tmp_arr);
    tvx=atof(tmp_arr[0]);
       tvy=atof(tmp_arr[1]);
    tvz=atof(tmp_arr[2]);
       Proj3Dto2D(tvx,tvy,tvz);
       position=(int(tvy)-1)*v_width+int(tvx);
    if(-10<(int(tvy-1)))
    {
          *(xx+i)=atof(tmp_arr[0]);
    *(yy+i)=atof(tmp_arr[1]);
    *(zz+i)=atof(tmp_arr[2]);
    i++;
    }
       else
    {
     if((position>=0) && (position<=v_width*v_height) && (*(formview+position)==0))
     {
              *(xx+i)=atof(tmp_arr[0]);
        *(yy+i)=atof(tmp_arr[1]);
        *(zz+i)=atof(tmp_arr[2]);
        i++;
     *(formview+position)=1;
     }
    }
       total_num--;
    
}   
*kk=i-1;
FileInName.Close();
delete formview;
    //fclose(FileOutName);
}
在vb中用string就行,上例中还要注意的就是文件的处理.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值