免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6158 | 回复: 9
打印 上一主题 下一主题

[函数] 难道 IBM xlC 中的 STL vector 没有sort 函数? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-12-30 11:06 |只看该作者 |倒序浏览
编译时出错

1540-0274 (S) The name lookup for "sort" did not find a declaration.

同一个程序,在linux中编译、执行均没有问题。

[ 本帖最后由 hsia 于 2005-12-30 11:08 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2005-12-30 11:18 |只看该作者
xlc 我一直用来编译c代码的,C++也是用这个啊.
还有xlC_r之类的,好多,楼主去找找,或许有点帮助.

论坛徽章:
0
3 [报告]
发表于 2005-12-30 12:39 |只看该作者
本来标准的vector中就没有sort()成员。对于vector的排序,应该使用标准库的sort()算法。

论坛徽章:
0
4 [报告]
发表于 2005-12-30 17:24 |只看该作者
感谢楼上, 可能是我没有叙述清楚。我所用的应该就是STL中的算法,而不是成员函数。

我的部分代码如下:(在BCB 以及 linux 中均无问题)




  1. #ifdef __BORLANDC__
  2. #pragma hdrstop
  3. #include <condefs.h>
  4. #include <conio.h>
  5. #else
  6. # define stricmp(a,b) strcasecmp((a),(b))
  7. #endif

  8. #include <iostream>
  9. #include <vector>
  10. #include <string>
  11. #include <fstream>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>

  15. #define LN_BUF_SIZE 1024
  16. using namespace std;

  17. struct DKLrcdTYP
  18.     {
  19.     char YSDWSWJG[8];   // SWJGID="2220882"
  20.     char FPHM[8];
  21.     char KPRQ[12];
  22.     char KPJE[12];       
  23.     char XFSWSBH[16];
  24.     char GFSWSBH[16];

  25.     bool operator < (const DKLrcdTYP &m)const
  26.          {
  27.                 return (0>memcmp(YSDWSWJG,m.YSDWSWJG,16));
  28.          }
  29.     bool operator == (const DKLrcdTYP &m)const
  30.          {
  31.                 return (0==memcmp(YSDWSWJG,m.YSDWSWJG,16));
  32.          }
  33.     bool operator > (const DKLrcdTYP &m)const
  34.          {
  35.                 return (0<memcmp(YSDWSWJG,m.YSDWSWJG,16));
  36.          }
  37.     };
  38. bool less_XF(const DKLrcdTYP & m1, const DKLrcdTYP & m2)
  39. {
  40.   return( 0>memcmp(m1.YSDWSWJG,m2.YSDWSWJG,16));
  41. }
  42. vector <struct DKLrcdTYP> FPdkl(0);
  43. vector <struct DKLrcdTYP> FPcgl(0);

  44. //---------------------------------------------------------------------------

  45. * * * * * *

  46. int main(int argc, char **argv)
  47. {

  48.   
  49.   chgDKL_HZ();   // 获取 n 个 数据   FPdkl.push_back(DKLrcd);

  50.   sort(FPdkl.begin(), FPdkl.end(), less_XF);

  51. }

  52. * * * * * *

复制代码

[ 本帖最后由 hsia 于 2005-12-30 17:35 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2005-12-30 19:34 |只看该作者
#include <algorithm>

论坛徽章:
0
6 [报告]
发表于 2005-12-31 06:17 |只看该作者
非常感谢!

论坛徽章:
0
7 [报告]
发表于 2005-12-31 11:22 |只看该作者
非常感谢!

继续请教 whyglinux :

在xlC 中 使用STL ,编译时还需要连接什么库么?

[ 本帖最后由 hsia 于 2005-12-31 11:26 编辑 ]

论坛徽章:
0
8 [报告]
发表于 2005-12-31 13:08 |只看该作者
xlC应该会默认连接C++标准库,所以如果只是使用STL的话不需要再连接什么库了。

我对xlC不熟悉,你可自己实验一下,或者看编译器手册。

论坛徽章:
0
9 [报告]
发表于 2006-01-01 11:27 |只看该作者
连接时出了很多错。估计是STL库没连接上。而在LINUX里面却全无问题。

  1. ld: 0711-317 ERROR: Undefined symbol: Virtual table for class "__DynaCastDesc_si_public": first non-inline virtual function in "__DynaCastDesc_si_public" is not defined.
  2. ld: 0711-317 ERROR: Undefined symbol: Virtual table for class "eti_cplusplus": first non-inline virtual function in "eti_cplusplus" is not defined.
  3. ld: 0711-317 ERROR: Undefined symbol: operator delete(void*)
  4. ld: 0711-317 ERROR: Undefined symbol: .std::ios_base::Init::Init()
  5. ld: 0711-317 ERROR: Undefined symbol: .std::_Winit::_Winit()
  6. ld: 0711-317 ERROR: Undefined symbol: .std::ios_base::Init::~Init()
  7. ld: 0711-317 ERROR: Undefined symbol: .std::_Winit::~_Winit()
  8. ld: 0711-317 ERROR: Undefined symbol: std::cout
  9. ld: 0711-317 ERROR: Undefined symbol: .std::__setUncaughtExceptionFlagFb
  10. ld: 0711-317 ERROR: Undefined symbol: .__CleanupCatch
  11. ld: 0711-317 ERROR: Undefined symbol: .operator delete(void*)
  12. ld: 0711-317 ERROR: Undefined symbol: .std::_Lockit::_Lockit(int)
  13. ld: 0711-317 ERROR: Undefined symbol: .std::locale::_Getfacet(unsigned long) const
  14. ld: 0711-317 ERROR: Undefined symbol: .__Throw
  15. ld: 0711-317 ERROR: Undefined symbol: .std::unexpected()
  16. ld: 0711-317 ERROR: Undefined symbol: .std::terminate()
  17. ld: 0711-317 ERROR: Undefined symbol: .__ReThrow
  18. ld: 0711-317 ERROR: Undefined symbol: .std::uncaught_exception()
  19. ld: 0711-317 ERROR: Undefined symbol: .std::_Lockit::~_Lockit()
  20. ld: 0711-317 ERROR: Undefined symbol: std::locale::id::_Id_cnt
  21. ld: 0711-317 ERROR: Undefined symbol: .operator new(unsigned long)
  22. ld: 0711-317 ERROR: Undefined symbol: .std::ios_base::clear(int)b
  23. ld: 0711-317 ERROR: Undefined symbol: std::ctype<char>::id
  24. ld: 0711-317 ERROR: Undefined symbol: .std::_Locinfo::_Locinfo(const char*)
  25. ld: 0711-317 ERROR: Undefined symbol: .std::_Locinfo::~_Locinfo()
  26. ld: 0711-317 ERROR: Undefined symbol: std::ctype<char>::_Cltab
  27. ld: 0711-317 ERROR: Undefined symbol: .operator new(unsigned long,void*)
  28. ld: 0711-317 ERROR: Undefined symbol: ._Getctype
  29. ld: 0711-317 ERROR: Undefined symbol: .std::_String_base::_Xran() const
  30. ld: 0711-317 ERROR: Undefined symbol: .std::_String_base::_Xlen() const
  31. ld: 0711-317 ERROR: Undefined symbol: ._Tolower
  32. ld: 0711-317 ERROR: Undefined symbol: ._Toupper
  33. ld: 0711-317 ERROR: Undefined symbol: .operator new[](unsigned long)
  34. ld: 0711-317 ERROR: Undefined symbol: .operator delete[](void*)
  35. ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.

复制代码

[ 本帖最后由 hsia 于 2006-1-1 11:28 编辑 ]

论坛徽章:
0
10 [报告]
发表于 2008-02-08 22:14 |只看该作者
编译时加上
  1. -blibpath:"/usr/vacpp/lib:/usr/lib:/lib"
复制代码

就OK了

[ 本帖最后由 hsia 于 2008-2-8 22:15 编辑 ]

评分

参与人数 1可用积分 +3 收起 理由
langue + 3 我很赞同

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP