string array
-
how to return string array from a method? CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...? JAYARAJ
J5121982 wrote:
CString strarr[]={"JAYARAJ","bala"}
What are you trying to do here?
strarr
is not an array like you might think. If you need an array ofCString
objects, useCStringArray
. Otherwise, you'll need something like:char *strarr[] = {"JAYARAJ", "bala"};
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
-
how to return string array from a method? CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...? JAYARAJ
-
how to return string array from a method? CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...? JAYARAJ
-
You could use a vector of CStrings:
vector<CString> Doit()
{
CString s;
vector<CString> a;
s = "as";
a.push_back(s);
s = "ass";//this one is for my boss.
a.push_back(s);
return a;
}Now to use it:
CString s;
vector<CString> a;
a = Doit();this is this.
khan++ wrote:
s = "ass";//this one is for my boss.
:laugh: Watch out! He might be reading Code Project... :-D
-
khan++ wrote:
s = "ass";//this one is for my boss.
:laugh: Watch out! He might be reading Code Project... :-D
-
:-D Actually I have never seen him. And as far as I can tell, I am still anonymous. this is this.
-
Birthday : Friday 16th December, 1977
Location : Pakistanunless those informations are false, you're not really anonymous... ;)
-
sorry, i did not see any red bold stamp saying...
[CONFIDENTIAL] [DO NOT OPEN]
...so, i read it... :rolleyes:
-
Your function returns _one_ CString, not an array.
CStringArray myclass::getStr()
{
CStringArray csa;
csa.Add("str1");
csa.Add("str2");
return csa;
}~RaGE(); -- modified at 8:55 Thursday 30th March, 2006 : Sorry David, you posted while I was writing.
-
i got this error what to do? error C2558: class 'CStringArray' : no copy constructor available JAYARAJ
-
how to return string array from a method? CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...? JAYARAJ
J5121982 wrote:
CString myclass::getStr() { CString strarr[]={"JAYARAJ","bala"} return strarr; } i get error .. how to do it...?
Of course u have type conflict. It look like you wrote int myclass::getInt() { int arr[]={1,1} return arr; } May be this helps:
CString[] myclass::getStr()
{
CString strarr[]={"JAYARAJ","bala"}
return strarr;
}It should work, if no then try this
CString *myclass::getStr()
{
CString strarr[]={"JAYARAJ","bala"}
return (CString *)strarr;
}BTW strarr seems to have local scope. So what you want to return is unclear. If I understand what you try to do, it better to declare it in class itself:
class myclass{
...
public: /*private if you want*/
CString strarr[]={"JAYARAJ","bala"}....
}
or specify static class storage
CString[] myclass::getStr()
{
static CString strarr[]={"JAYARAJ","bala"}
return strarr;
}-- modified at 2:42 Friday 31st March, 2006 -- modified at 2:48 Friday 31st March, 2006