LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1068|回复: 2

看一看这代码为何在GCC下无法编译!!

[复制链接]
发表于 2003-8-4 01:10:50 | 显示全部楼层 |阅读模式
代码如下:
#include <iostream>
#include <cstring>
#include <string>
using namespace std;

void replaceAll(string &src,const string &findstr,const string &replstr)
{
        int found = src.find(findstr);
        while(found != string::npos)
        {
                src.replace(found,findstr.length(),replstr);
                found = src.find(findstr);
        }

}

void urldecode(string &s)
{
        replaceAll(s,"%2C",",");
        replaceAll(s,"%0D%0A","\n");
        replaceAll(s,"+"," ");
       
}

void split(const string &s,char *delim,string dest[])
{
        string temp = s;
        int count = 0;
        char *p;
        p = strtok(temp.begin(),delim);
        while(p!=NULL)
        {
                dest[count] = p;
                count++;
                p = strtok(0,delim);
        }
        for(int temp=0;temp != count;temp++)
                dest[temp].erase(0,dest[temp].find("=")+1);
}

int main()
{
        string s;
        count << "Enter encode string : ";
        cin >> s;
        cin.ignore();
        urldecode(s);
        string dest[2];
        split(s,"&",dest);
        cout << "N1 has the value: " << dest[0] << endl;
        cout << "N2 has the value: " << dest[1] << endl;
        return 0;
}

在GCC下编译,错误信息如下:
[langjian@localhost NIIT]$ g++ -o 10D2 10D2.cc
10D2.cc: In function `void split(const std::string&, char*, std::string*)':
10D2.cc:30: cannot convert `__gnu_cxx::__normal_iterator<char*,
   std::basic_string<char, std::char_traits<char>, std::allocator<char> > >' to
   `char*' for argument `1' to `char* strtok(char*, const char*)'
10D2.cc: In function `int main()':
10D2.cc:44: invalid operands of types `<unknown type>' and `const char[23]' to
   binary `operator<<'

但是这代码在VC++ 6.0中去顺利通过!
还望各位高手多多指教!
谢谢!
发表于 2003-8-4 07:41:28 | 显示全部楼层
我不想重复回答你的问题,看看我在linuxaid上的回答:
http://www.linuxaid.com.cn/forum/showdoc.jsp?l=1&i=70345
 楼主| 发表于 2003-8-5 02:35:31 | 显示全部楼层
多谢版主!
已成功编译!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表