Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

returning an array of CString

Posted on 2000-04-11
5
Medium Priority
?
345 Views
Last Modified: 2013-11-20
I'm still fairly new to MFC and would like to know how to declare a function that returns a CString array and actually create the function that returns the CString array.  How would I do that???
0
Comment
Question by:tblackwe
5 Comments
 

Expert Comment

by:kakamna
ID: 2704618
You have to use the pointer object of CString You can try

Decalre as
MyCLass{

CString * MyFunction()
CString *str;//where *str points to the //array of CString

}

CString * MYClsss::MyFunction()
{
return str;
}
0
 

Accepted Solution

by:
kakamna earned 100 total points
ID: 2704620
You have to use the pointer object of CString You can try

Decalre as
MyCLass{

CString * MyFunction()
CString *str;//where *str points to the //array of CString

}

CString * MYClsss::MyFunction()
{
return str;
}
0
 

Author Comment

by:tblackwe
ID: 2704678
So if I have a function:

CString* MyFunc()
{
CString [5] values;

values[0] = "one";
values[1] = "two";
values[2] = "three";
values[3] = "four";
values[4] = "five";

CString* rValues = values;
return rValues;
}

If the calling program says:

int main
{
CString* vals = MyFunc();

how do I now access the individual elements of the array?
0
 
LVL 1

Expert Comment

by:MT_MU
ID: 2704969
Just a comment.  In your above example the array values will be allocated on the stack - and will be discarded when you exit MyFunc();

To preserve it you would need to make it

static CString[5] values;

To access an indivual element in your main use

vals[index];
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 2706872
void GetStrings(CStringArray& rgs)
{
    rgs.Add("One");
    rgs.Add("Two");
    rgs.Add("Three");
}

void Test()
{
    CStringArray rgs;
    GetStrings(rgs);
    for(int i=0;i<rgs.GetSize();i++)
        TRACE("String %d = %s\n", i, rgs[i]);
}
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question