免费注册 查看新帖 |

Chinaunix

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

为什么编译无法通过呢? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-08 12:09 |只看该作者 |倒序浏览
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
//#include

//bool D(int a ,int b){return a<B;}

using namespace std;
int main()
{
  int A[] = {8, 7, 6, 5, 4, 3, 2, 1};
  const int N = sizeof(A) / sizeof(int);

while(next_permutation(A,A+8,less<int>)){
  copy(A, A+N, ostream_iterator<int>(cout, " "));
  cout<<endl;
  }
  copy(A, A+N, ostream_iterator<int>(cout, " "));
  return 0;
}

出错信息说是less<int>这里出错了,真搞不明白,烦请大家指教!

论坛徽章:
0
2 [报告]
发表于 2009-12-08 12:25 |只看该作者
完整错误信息

论坛徽章:
0
3 [报告]
发表于 2009-12-08 13:06 |只看该作者

回复 #2 雨过白鹭洲 的帖子

error:expected primary-expression before ‘>' token
在while那一行

论坛徽章:
0
4 [报告]
发表于 2009-12-08 19:01 |只看该作者
少了一个括号,less<int>只有一个default constructor
http://www.sgi.com/tech/stl/less.html

  1. #include <algorithm>
  2. #include <functional>
  3. #include <iostream>
  4. #include <iterator>
  5. //#include

  6. //bool D(int a ,int b){return a<B;}

  7. using namespace std;
  8. int main()
  9. {
  10.       int A[] = {8, 7, 6, 5, 4, 3, 2, 1};
  11.         const int N = sizeof(A) / sizeof(int);

  12.         while(next_permutation(A,A+N,less<int> ( ) )){
  13.               copy(A, A+N, ostream_iterator<int>(cout, " "));
  14.                 cout<<endl;
  15.                   }
  16.           copy(A, A+N, ostream_iterator<int>(cout, " "));
  17.             return 0;
  18. }
复制代码

[ 本帖最后由 churchmice 于 2009-12-8 19:07 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2009-12-10 17:47 |只看该作者

回复 #4 churchmice 的帖子

谢谢你,可以了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP