我的编译器发出错误“无法找到'ostream :: write(S1,int)'的匹配项” 在此代码中。编译器发出错误的部分被注释
#include<iostream.h>
#include<stdlib.h>
int main()
{
struct S1
{
char*str;
S1*ptr;
};
S1 arr[]={" Aanna ",arr+1," Neha ",arr+2," Simran ",arr};
S1*p[3];
for(int i=0;i<3;++i)
p[i]=arr[i].ptr;
cout.write(p[0]->str,7).put('\n');
cout.write((*p)->str,7).put('\n');
cout.write(**p,7).put('\n');//why doesn't it work
return 0;
}
答案 0 :(得分:6)
**p
的类型为S1
。没有ostream::write
的重载版本知道S1
,因此您收到错误消息。
我会站出来猜猜你打算放p[0]->ptr->str