Array and string type

M

Mystic

Hi,
I d like to know if it s possible to return a string array.
ex :
int ::first()
{
string myAr[2];

myAr = func();

}

string ::func()
{
string ar[2] = {"xXx", "Zone"};

return ar;
}
 
R

Rolf Magnus

Mystic said:
Hi,
I d like to know if it s possible to return a string array.
No.

ex :
int ::first()
{
string myAr[2];

myAr = func();

You can't assign to arrays.
}

string ::func()
{
string ar[2] = {"xXx", "Zone"};

return ar;
}

You sould use std::pair<std::string>. If you have more than two, use
std::vector<std::string>.
 
J

Jeff Schwab

Rolf said:
Mystic wrote:

Hi,
I d like to know if it s possible to return a string array.

No.


ex :
int ::first()
{
string myAr[2];

myAr = func();


You can't assign to arrays.

}

string ::func()
{
string ar[2] = {"xXx", "Zone"};

return ar;
}


You sould use std::pair<std::string>.

The standard declaration of pair needs two types, not just one.

#include <string>
#include <utility>

typedef std::pair said:
If you have more than two, use std::vector<std::string>.

Or use a struct to wrap your array, and return the struct by value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,167
Messages
2,570,910
Members
47,453
Latest member
MadelinePh

Latest Threads

Top