On Mon, Oct 20, 2014 at 2:17 PM, Gustaf Granath <gustaf.gran...@gmail.com> wrote:
> Hi > Im trying to use some C++ functions in R. However, these functions are > build around unsigned char* variables (1D array). I have for example a > large matrix in R that represents black (e.g. 1-bit image, 0 and 1s). I > cant find a solution to convert a character vector into unsigned char* > within Rcpp. Im new to Rcpp and C++ so I might have missed something > obvious here. Please direct me to resources on this topic (google did not > help much). > > A start: > > SEXP test(SEXP cM){ > CharacterVector Vc(cM); > int n = Vr.size(); > RawVector x(n); //is this the same as unsigned char* ? > //I tried to fill it with char*(Mr) but I > didnt succeed > } > I tend to go through the standard library as its less of a black box. Try creating a std::string and appending your chars to that string. Then call obj.c_str() to get the C-style array of chars. Or push the chars onto a std::vector and do something like &obj[0] to get a 1-D array. THK > > Thanks, > > Gustaf > > -- > Gustaf Granath (PhD) > Post doc > McMaster University > School of Geography & Earth Sciences > > _______________________________________________ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel > -- http://www.keittlab.org/
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel