Passing a array of std::string by reference

arrays, c++, string

Solution

Here's how!

//Change the 10 to whatever size you'd like
void changeStr(std::string (&str)[10]) {
}

This of course, is for a static size, the other answers, however, are better methods accomplishing what you need with flexibility.

Problem

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...

Original source