<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 20, 2014 at 2:17 PM, Gustaf Granath <span dir="ltr"><<a href="mailto:gustaf.granath@gmail.com" target="_blank">gustaf.granath@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi<br>
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).<br>
<br>
A start:<br>
<br>
SEXP test(SEXP cM){<br>
  CharacterVector Vc(cM);<br>
  int n = Vr.size();<br>
  RawVector x(n); //is this the same as unsigned char* ?<br>
                            //I tried to fill it with char*(Mr) but I didnt succeed<br>
}<br></blockquote><div><br></div><div>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.</div><div><br></div><div>THK</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks,<br>
<br>
Gustaf<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Gustaf Granath (PhD)<br>
Post doc<br>
McMaster University<br>
School of Geography & Earth Sciences<br>
<br>
______________________________<u></u>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-<u></u>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-<u></u>project.org/cgi-bin/mailman/<u></u>listinfo/rcpp-devel</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><a href="http://www.keittlab.org/" target="_blank">http://www.keittlab.org/</a></div>
</div></div>