The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 How can I pass String Array?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
winflowers Posted - 09/28/2004 : 11:58:32 AM
Origin Version (Select Help-->About Origin): 7.5
Operating System: windows 98
I make a function to collect all worksheet names under active folder and store them in a string array. But how can I use this string array in other functions?
4   L A T E S T    R E P L I E S    (Newest First)
winflowers Posted - 09/29/2004 : 08:32:45 AM
Great! This is exactly what I want!
I don't like vector<string> test(), so I don't satisfied with my code although it works.
Thank you guys for your help. It's realy a good forum.
Mike Buess Posted - 09/29/2004 : 08:02:29 AM
Your code works fine so I'm not sure what you are asking. Do you want an alternative to vector<string> test()? This will work...
void test(SringArray &sa) 
{
sa.SetSize(3);
sa[0] = "one";
sa[1] = "two";
sa[2] = "three";
}
void test2() 
{
StringArray sa;
test(sa);
for(int ii = 0; ii < sa.GetSize(); ii++)
out_str( sa[ii] );
}


Mike Buess
Origin WebRing Member
winflowers Posted - 09/29/2004 : 03:30:18 AM
Thank you very much for your code, Easwar! But that is not what I exactly want. What I want is that test() is an indepentant function, and I would like to use this function in other functions, for example test2() . Maybe I didn't say it clearly. The following code can do it.

vector<string> test()
{
vector<string> sa(3);
sa[0] = "one";
sa[1] = "two";
sa[2] = "three";
return sa;
}
void test2()
{
vector<string> sa2;
sa2 = test();
for(int ii = 0; ii < sa2.GetSize(); ii++)
out_str( sa2[ii] );
}

When I run test2(), I can get the results for test(). Or is there any other code can do this as well?
easwar Posted - 09/28/2004 : 12:52:27 PM
Hello,

StringArray is just a vector of type string, and so you can write code such as:


void test()
{
StringArray sa(3);
sa[0] = "one";
sa[1] = "two";
sa[2] = "three";
test2( sa );
}

void test2(StringArray& sa)
{
for(int ii = 0; ii < sa.GetSize(); ii++)
out_str( sa[ii] );
}




which is same as:


void test()
{
vector<string> sa(3);
sa[0] = "one";
sa[1] = "two";
sa[2] = "three";
test2( sa );
}

void test2(vector<string>& sa)
{
for(int ii = 0; ii < sa.GetSize(); ii++)
out_str( sa[ii] );
}



Easwar
OriginLab




The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000