Thrust vector of struct

Hello everyone,
I created a thrust device vector of a structs and i am not able to print it.Please help.

The struct goes:

struct point
{
int x;
int y;
};

And the device vector implementation goes:

thrust::host_vector<point> C3(10);
thrust::device_vector<point> D3 = C3;
point *d_c3=thrust::raw_pointer_cast(D3.data());

//Trying to print below
for(int i=0;i<D3.size();i++)
		cout<<"\n"<<D3[i].x;             //Line with error
	cout<<endl;

The error shown is :
class “thrust::device_reference” has no member “x”

Do this instead:

for(int i=0;i<D3.size();i++)
             {   point temp = D3[i];
		cout<<"\n"<<temp.x;    }
	cout<<endl;

Yes it works. Thank You. :)
But i was informed with the following way to do this which looks more efficient :

cout<<"\n"<<static_cast<point>(D3[i]).x;

Presumably you’re not worried about efficiency with cout.

In general, either realization is triggering under-the-hood device->host copies. Neither is particularly efficient, since a separate device->host copy will occur with each loop iteration, for either method.

If you want to make this “more efficient”, transfer the entire vector at once, in a single operation, then print out from there:

thrust::host_vector<point> C3(10);
thrust::device_vector<point> D3 = C3;
point *d_c3=thrust::raw_pointer_cast(D3.data());

thrust::host_vector<point> H3 = D3;  // copy entire vector to host, all at once
//print from host data
for(int i=0;i<H3.size();i++)
		cout<<"\n"<<H3[i].x; 
	cout<<endl;

this will be “more efficient” from the standpoint of device->host copying

For this trivial example, you could have just as easily used C3 instead of H3, but presumably in your real code, some modification of the data occurs in the D3 vector, which you then want to print out.