<分区>
假设我想编写一个 C++ 函数 foo() 来更新输入字符串的值。我该怎么做?代码可能看起来像我下面的代码,但我不知道如何正确传递字符串,以便它由函数更新。
void foo(String x) // Not sure if I should put an & or * before x
{
x += " Goodbye";
}
void main()
{
String x = "Hello World";
cout << "x = " << x << endl;
foo(x); // Not sure if I should pass a pointer to x,
// a reference to x or what?
cout << "After foo (), x = " << x << endl;
}
(仅供引用,我正在为 Arduino 处理器编写此代码)