代码反转Char数组。例如,如果我写: char str [] ="反向&#34 ;; 它将返回" esreveR"在控制台中,现在我想知道,我是否以及如何用字符串填充它?
我尝试的是:char str [] = userInput; (但它显然没有用......)
library(tmap)
data(Europe)
tm_shape(Europe) +
tm_fill("gdp_cap_est", title = "GDP", style = "fixed",
breaks = c(0, 10000, 20000, 30000, 40000, Inf),
textNA = "Dunno",
colorNA = "green", # <-------- color for NA values
palette = c("red", "orange", "yellow", "turquoise", "blue", "white")) +
tm_borders() +
tm_layout("Wealth (or so)",
legend.title.size = 1,
legend.text.size = 0.6,
legend.position = c("left","bottom"),
legend.bg.color = "white",
legend.digits = 5,
legend.bg.alpha = 1)
答案 0 :(得分:3)
在您的代码中,userInput
是std::string
,您的函数需要char *
。
不考虑如何更改代码以获得更好的代码,将字符串作为char *
:
char *str = new char[userInput.length() + 1];
strcpy(str, userInput.c_str());
最后不要忘记delete str;
。