注册 登录
编程论坛 C++教室

VC 6.0上能通过,DEV C++无法通过……

love24114 发布于 2012-01-15 09:09, 551 次点击
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int cmp(const void *a,const void *b)
{
    return *(int *)a-*(int *)b;
}
int find(vector<int> a,int Bfind)
{
    int i;
    for (i=0;i<a.size();i++)
        if (a[i]==Bfind)
            return 1;
    return 0;
}
int main()
{
    int n,i;
    int temp;
    cin>>n;
    vector<int> a;
    for (i=0;i<n;i++)
    {
        cin>>temp;
        if (a.empty())
            a.push_back(temp);
        else if (!find(a,temp))
            a.push_back(temp);
    }
    qsort(a.begin(),a.size(),4,cmp);
    for (i=0;i<a.size();i++)
        cout<<a[i]<<" ";
    return 0;
}

[ 本帖最后由 love24114 于 2012-1-15 09:11 编辑 ]
3 回复
#2
Evander2012-01-15 23:14
VC++6.0对标准化C++的兼容仅达83.43%。
而仅仅是GCC3.3对标准化C++的支持达96.15%。
可想而知,楼主的问题很有可能是因为编译器对标准支持的问题所导致的。

参考百度百科:http://baike.baidu.com/view/1576342.htm#2
#3
lz10919149992012-01-15 23:26
不能用qsort,qsort是针对数组进行排序的,并不是容器。
#4
rjsp2012-01-16 08:41
3楼说得对,你应该用 std::sort,而非 qsort
如果一定要用 qsort,试试 qsort( &a[0], a.size(), 4, cmp );
1