藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 應用編程


    

藍森林 http://www.lslnet.com 2006年6月6日 10:18


大家看看,為什麼我在vc++6.0使用substr出錯,錯在哪裡

value=&substr(str,i,j-i);
我想把字符串str中從第i個字符開始的長度為(j-i)的子串複製vlaue;
可是為什麼會出錯呢
報錯如下
error C2065: 'substr' : undeclared identifier
error C2440: '=' : cannot convert from 'int *' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
錯在哪裡,我應該怎麼改呢?

大家看看,為什麼我在vc++6.0使用substr出錯,錯在哪裡

你看看substr的原型吧。
還有你包含它的頭文件了嗎?

大家看看,為什麼我在vc++6.0使用substr出錯,錯在哪裡

頭文件是STRING.H吧,我已經包含它了呀。

大家看看,為什麼我在vc++6.0使用substr出錯,錯在哪裡

好像string.h裡面沒這個函數吧。

大家看看,為什麼我在vc++6.0使用substr出錯,錯在哪裡

除了上面的錯誤外,下面的更是錯得離譜啊!
value=&substr(str,i,j-i);

???Get the address of a function call in C??

大家看看,為什麼我在vc++6.0使用substr出錯,錯在哪裡

我是想把字符串str中的第i個字符開始到第j個字符的子串複製到value中,大蝦們教教我該怎麼做啊

大家看看,為什麼我在vc++6.0使用substr出錯,錯在哪裡

用strncpy()。

大家看看,為什麼我在vc++6.0使用substr出錯,錯在哪裡

int SubStr(char *source,char *temprecord,int begin,int end,char *errmsg)
{
        int     SourceLen;
        char chErrMsg[300];
        SourceLen=strlen(source);
    if(end>;SourceLen)
    {
        sprintf(chErrMsg,"數據非法,END大於字符串:%s的長度",source);
        WriteErrLog("SubStr:",chErrMsg);
        return -1;
    }
    strncpy(temprecord,source+begin-1,(end-begin+1));
    temprecord[end-begin+1]='\0';
    if((strcmp(temprecord,""))==0)return -1;
    return 0;
}



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com