请问这个结构体哪里错了?

bitbit47 2010-01-27 04:59:57
#include <string.h>
void main()
{
struct packet
{
string hash_data;//错误提示处
packet *left_child;
packet *right_child;
}packet_tree[4][8];
}
编译出错:提示两个错误:
1.C++ does not support default-int
2.missing ';'before identifier hash_data;

请高手指教。
...全文
123 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
WPooh 2010-01-27
  • 打赏
  • 举报
回复
应该将string.h改成string,并且加上"using namespace std;".
flyerwing 2010-01-27
  • 打赏
  • 举报
回复

#include "stdafx.h"
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
struct packet
{
string hash_data;//错误提示处
packet *left_child;
packet *right_child;
}packet_tree[4][8];
return 0;
}

这个好象没错了
londy_2000 2010-01-27
  • 打赏
  • 举报
回复
string.h是C中的字符串函数的头文件,C++中的<string>才可有string类型吧
xy_sun 2010-01-27
  • 打赏
  • 举报
回复
void main()
改成
int main()
fight_flight 2010-01-27
  • 打赏
  • 举报
回复
#include <string>
using namespace std;
void main()
{
struct packet
{
string hash_data;//错误提示处
packet *left_child;
packet *right_child;
}packet_tree[4][8];
}
ssdx 2010-01-27
  • 打赏
  • 举报
回复
std::string

或者
using namespace std;
cismylife 2010-01-27
  • 打赏
  • 举报
回复
#include <string>
c-free测试通过
djlxue 2010-01-27
  • 打赏
  • 举报
回复
string是C++的标准库,要加命名空间
可以用
using namespace std;
也可以使用
std::string;
lvp1984 2010-01-27
  • 打赏
  • 举报
回复
1 #include <string>
2
3 using std::string;
4
5 class packet;
6
7 int main()
8 {
9 struct packet
10 {
11 string hash_data;
12 packet *left_child;
13 packet *right_child;
14 }packet_tree[4][8];
15
16 return 0;
17 }


gcc 没问题
djlxue 2010-01-27
  • 打赏
  • 举报
回复

#include <string>
using namespace std;
void main()
{
struct packet
{
string hash_data;
packet *left_child;
packet *right_child;
}packet_tree[4][8];
}


vs2008测试通过……
ithiker 2010-01-27
  • 打赏
  • 举报
回复
string的问题,结构体改成这样就没问题了,我也不知道为什么

struct packet
{
char* hash_data;
packet *left_child;
packet *right_child;
}packet_tree[4][8];

bitbit47 2010-01-27
  • 打赏
  • 举报
回复
和头文件没关系吧?我改过了,没用。我用的是vs2005
traceless 2010-01-27
  • 打赏
  • 举报
回复
你确定这样会错 ?

或者你使用的是vc6
ithiker 2010-01-27
  • 打赏
  • 举报
回复
头文件改成#include <string>试试

64,651

社区成员

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

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