I want to write k elements starting from k*i to a file. so in a for loop I write as below:
testOut.write((char*) h_test[k*i] ,k*sizeof(float));
I get this error “invalid cast from type ‘float’ to type ‘char*’ “
How should I correct this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to write them in binary, you can do as follows:
h_test + k*iis the address of afloatpointer, that you reinterpret to aconst char*so thatwritecan take it. Note that adding to a pointer increments the pointer taking into account the pointed element size, and you convert the pointer after.Finally,
writeaccepts aconst char*, notchar*.