string-array functions

Hey out there,

I would like you to ask if you could use a string-array as return type.

I'd think at something like this:

string function[50]()
yeah you can make string functions which return string arrays.
For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

string line[5] = {"   ", "   ", "   ", "   ", "   " };
//string array "line" declared

string Something(int x, string line[5]) 
{
line[x] = "Hi!";
return line[x];
}
//"Something" function assignes "Hi" to one member of the string-array "line"

int main()
{
Something(5, line);
cout<<line[1]<<line[2]<<line[3]<<line[4]<<line[5]<<endl; //every member of "line" is printed
system("pause");
return 0;
}


the Something function will assign "Hi!" to one of the 5 positions of the string-array,
and return the modified string-array member to main.
Then main will print out the whole string-array.



Last edited on
The only two limits on the return types of functions in C++ are that they cannot be function types and cannot be array types (but can be references to such things)

Return a std::vector<std::string> instead, or an std::array<std::string, 50> (also known as boost::array for older compilers)
Last edited on
cool! thanks a lot you two.
Topic archived. No new replies allowed.