求助 求助 有关string的问题

hnczhyh 2008-02-23 12:04:05
我编写了一段代码:
BYTE ftry[] = { 0x10,0x03,0x74,0x72,0x79,0x04 };
string sFlag_try( ftry, ftry + sizeof(ftry)/sizeof(ftry[0]) );
//将字符串str内“始于位置stridx”的部分当作字符串的初值string s(str,stridx)
BYTE fadd[] = { 0x10,0x03,0x61,0x64,0x64,0x04 };
string sFlag_add( fadd, fadd + sizeof(fadd)/sizeof(fadd[0]) );

BYTE fclear[] = { 0x10,0x05,0x63,0x6c,0x65,0x61,0x72 };
string sFlag_clear( fclear, fclear + sizeof(fclear)/sizeof(fclear[0]) );

BYTE flost[] = { 0x10,0x04,0x6C,0x6F,0x73,0x74,0x04 };
string sFlag_lost( flost, flost + sizeof(flost)/sizeof(flost[0]) );

BYTE fiteminfo[] = { 0x42,0x11,0x3B,0x26,0x11,0x94 };
string sFlag_iteminfo( fiteminfo, fiteminfo + sizeof(fiteminfo)/sizeof(fiteminfo[0]) );
但是在编译的时候:
error C2664: '__thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::std::basic_string<char,struct std::char_traits<char>,class std::allocator
...全文
95 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hnczhyh 2008-02-23
  • 打赏
  • 举报
回复
如果是这样的话就想哭了,
hnczhyh 2008-02-23
  • 打赏
  • 举报
回复
啊,我的是vc 6.0
星羽 2008-02-23
  • 打赏
  • 举报
回复

BYTE ftry[] = { 0x10,0x03,0x74,0x72,0x79,0x04 };
string sFlag_try = (char*)ftry;

cout<<sFlag_try<<endl;


星羽 2008-02-23
  • 打赏
  • 举报
回复
我用vs2005是可以编译过的,只不过输出乱码
hnczhyh 2008-02-23
  • 打赏
  • 举报
回复
error C2664: '__thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(const char
hnczhyh 2008-02-23
  • 打赏
  • 举报
回复
不行.也是一样的
星羽 2008-02-23
  • 打赏
  • 举报
回复

这个能编译过吗?

#include "string"
#include "windows.h"
using namespace std;

int main()
{
BYTE ftry[] = { 0x10,0x03,0x74,0x72,0x79,0x04 };
string sFlag_try( ftry, ftry + sizeof(ftry) / sizeof(ftry[0]) );

cout<<sFlag_try<<endl;

return 0;
}


hnczhyh 2008-02-23
  • 打赏
  • 举报
回复
也就是BYTE转换成string这种,郁闷了一天,那位大哥教教
hnczhyh 2008-02-23
  • 打赏
  • 举报
回复
求助,求助,还有
string sBloodRaiderPersonnelTransportWreck( fBloodRaiderPersonnelTransportWreck, fBloodRaiderPersonnelTransportWreck + sizeof(fBloodRaiderPersonnelTransportWreck)/sizeof(fBloodRaiderPersonnelTransportWreck[0]) );

提示错误:
cannot convert parameter 2 from 'unsigned char *' to 'unsigned int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
这两个地方搞了我一天都没有搞出来
就呆在云上 2008-02-23
  • 打赏
  • 举报
回复
先查看一下msdn
看看到底string这个类型可以用BYTE类型的构造否啊?
basic_string(
const value_type* _Ptr,
size_type _Count,
const allocator_type& _Al = Allocator ( )
);
basic_string(
const value_type* _Ptr,
const allocator_type& _Al = Allocator ( )
);
basic_string(
const basic_string& _Right,
size_type _Roff,
size_type _Count = npos,
const allocator_type& _Al = Allocator ( )
);
basic_string(
size_type _Count,
value_type _Ch,
const allocator_type& _Al = Allocator ( )
);
explicit basic_string(
const allocator_type& _Al = Allocator ( )
);
template<class _It>
basic_string(
_It _First,
_It _Last,
const allocator_type& _Al = Allocator ( )
);
basic_string(
const_pointer _First,
const_pointer _Last
);
basic_string(
const_iterator _First,
const_iterator _Last
);

64,642

社区成员

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

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