user3211362
user3211362

Reputation: 41

Why does this error occur in my code?

My compiler gives an error "Could not find a match for 'ostream::write(S1,int)'" in this code .The part where the compiler gives an error is commented

#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;
}

Upvotes: 0

Views: 50

Answers (1)

M.M
M.M

Reputation: 141648

**p has type S1. There is no overloaded version of ostream::write which knows about S1 , so you get an error.

I will go out on a limb and guess that you meant to put p[0]->ptr->str

Upvotes: 6

Related Questions