跪求指点 C++

theSongInTheMidnight 2009-04-02 06:39:26
#include<deque>
#include<string>
using namespace std;

main()
{string ch[]={"you","are","a","bitch","oh"};
deque<string> deq1(ch,ch+5);
return 0;
}


为什么错误呢?为什么不能用数组去初始化 deq1 呢?

而下面的程序却没有错误.

#include<list>
#include<string>
using namespace std;

main()
{string ch[]={"you","are","a","bitch","oh"};
list<string> lis1(ch,ch+5);
return 0;
}


跪求指点
...全文
107 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Paradin 2009-04-02
  • 打赏
  • 举报
回复
受教。
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 maenxiang 的回复:]
你用的是VC吧。反正6.0版本很不规范。用高一点的版本或者其他编译器试试

VC这个定义不符合规范:
typedef const_iterator _It;
deque(_It _F, _It _L, const _A& _Al = _A())
这个就限定了,不能用string *
规范中是要用模版函数的,模版函数的_It可以不是list::iterator。

list可以是应为这样写的。
list(const _Ty *_F, const _Ty *_L, const _A& _Al = _A())
所有可以用 string *
[/Quote]

是的.我在vS2008中没有报错!谢谢指点!
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 mengde007 的回复:]
deque的构造函数

Deque <Elem> c(beg,end)

[/Quote]

其中的beg=ch,end=ch+5;
那里有问题呢?请指点
mengde007 2009-04-02
  • 打赏
  • 举报
回复
现在给出deque的构造函数
deque<Elem> c
deque<Elem> c1(c2)
Deque<Elem> c(n)
Deque<Elem> c(n, elem)
Deque<Elem> c(beg,end)
楼主构造错了
  • 打赏
  • 举报
回复
VC6.0 错误提示是:

c:\documents and settings\administrator\桌面\sdfe.cpp(7) : error C2664: '__thiscall std::deque<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char
_traits<char>,class std::allocator<char> > > >::std::deque<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<c
har> > > >(unsigned int,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,const class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > &)' : cannot
convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > [5]' to 'unsigned int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
  • 打赏
  • 举报
回复
我查不到他们构造函数的更多细节啊.
大家指点啊..
我所能查到的就是俩个都可以.
但是deque实际上却不行,不知道为什么..

maenxiang 2009-04-02
  • 打赏
  • 举报
回复
你用的是VC吧。反正6.0版本很不规范。用高一点的版本或者其他编译器试试

VC这个定义不符合规范:
typedef const_iterator _It;
deque(_It _F, _It _L, const _A& _Al = _A())
这个就限定了,不能用string *
规范中是要用模版函数的,模版函数的_It可以不是list::iterator。

list可以是应为这样写的。
list(const _Ty *_F, const _Ty *_L, const _A& _Al = _A())
所有可以用 string *
damo_xu 2009-04-02
  • 打赏
  • 举报
回复
错误也贴上来好些。
随便说下:看看deque 的构造函数和list有什么不同。
Paradin 2009-04-02
  • 打赏
  • 举报
回复
不能直接用吧好像

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧