Solved

returning an array of CString

Posted on 2000-04-11
5
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 50 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 71
How do you programatically show and hide the Windows 10 On-Screen-Keyboard? 3 925
Expand data scrubbing tool 13 36
sum67 challenge 35 116
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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