错在那里!!!!

YOU2005 2006-08-13 11:13:51
#include "iostream.h"
void main()
{
struct abc
{
char name[20];
char job[20];
int age;
}ad1;

ad1.name[]="tom";
ad1.job[]="abc";
ad1.age=15;
cout<<ad1;
}


--------------------Configuration: 点的操作符 - Win32 Debug--------------------
Compiling...
点的操作符.cpp
D:\VC\点的操作符.cpp(13) : error C2059: syntax error : ']'
D:\VC\点的操作符.cpp(14) : error C2059: syntax error : ']'
D:\VC\点的操作符.cpp(16) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'struct main::abc' (or there is no acceptable conversion)
执行 cl.exe 时出错.
...全文
115 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qtext 2006-08-14
  • 打赏
  • 举报
回复
插入一个什么?
vcPlayer 2006-08-14
  • 打赏
  • 举报
回复
怎么又插入了一个?

我指的是qtext() 。
believefym 2006-08-14
  • 打赏
  • 举报
回复
char *p;
p = "abc";
vcPlayer 2006-08-14
  • 打赏
  • 举报
回复
楼上正解。
believefym 2006-08-14
  • 打赏
  • 举报
回复
或者把
char name[20];
char job[20];
改成指针char*
qtext 2006-08-14
  • 打赏
  • 举报
回复
ad1.name[]="tom";
ad1.job[]="abc";
上面这二句及cout有问题,不能这样写
#include "iostream.h"
#include <string.h>
void main()
{
struct abc
{
char name[20];
char job[20];
int age;
}ad1;

strcpy(ad1.name,"tom");
strcpy(ad1.job,"abc");
ad1.age=15;
cout<<ad1.name<<endl<<ad1.job<<endl<<ad1.age;
}

变成这样就可以了。

64,654

社区成员

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

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