CString a;
a="c:\\mypicture\\20.bmp";
int c;
想得到c=20,而且当a="c:\\mypicture\\a\\20.bmp";
同样得到c=20,怎么办?
         ~~~~~~~~~~毕业设计  急用!!!!  

解决方案 »

  1.   

    use CFile.GetFileTitle
    then convert string to int(use atoi)
      

  2.   

    CString str = "d:\\xx\\xfd\\20.bmp\\20.xx";
    CString temp;
    int c;
    c=str.FindOneOf("20");
    temp=str.Mid(c,2);
    c=atoi(temp);
      

  3.   

    你的意思就是得到文件的标题并且把它转换为整数是吧?
    下面的算法基于合理的解释,比如a = "c:\\mypicture\\2m0.bmp"属于不合理的解释
    第一步:得到标题字符串 <以a = "c:\\mypicture\\20.bmp"为例>
    int f = a.ReverseFind('\\');  // f = 12;
    CString b;
    b = a.Right(a.GetLength()-(f+1)); // b = "20.bmp";
    f = b.ReverseFind('.'); // f = 2;
    b = b.Left(f); // b = "20";
    第二步:把字符串转换为整数
    sscanf((LPCTSTR)b, "%d", &c); // c = 20;
    程序通过验证,不过我不太清楚最后一步的转换'(LPCTSTR)b'是否一定合理,还望高手可以指点。