【发布时间】:2015-03-10 19:58:18
【问题描述】:
我被难住了。这个实在想不通。
int main(){
string blah = "text";
example(&blah);
}
void example(string *h){
*h[3]='l';
}
我在上面的函数中试图做的是在不使用全局变量的情况下编辑原始字符串的第 4 个字符。我原以为这会起作用,因为我知道我可以用整数做类似的事情。猜测这与字符串/字符转换有关,但我在网上找不到太多信息。
【问题讨论】:
-
运算符优先级:
(*h)[3]。但是,如果您想让它变得简单,请通过引用传递:void example(string& h) { h[3] = '1'; }。 -
std::string*eeewwww...