I'ld like to create a function that passes not a std::string by reference to be modified,
void changeStr(std::string &str)
{
str = "Hello World!";
}
, but rather an entire, fixed-sized array of std::strings (the function will do exactly the same: attribute some specific strings to each space in the array). But I don't know which is the appropriate syntax...
Since you're using C++ you probably want to pass a collection of values by reference instead of a collection of references by reference. The easiest way to achieve this is to use std::vector<T>
void changeStr(std::vector<std::string>& collection) {
if (collection.size() > 0) {
collection[0] = "hello world";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With