Solved

returning an array of CString

Posted on 2000-04-11
5
336 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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 54
Separate into files by filename 12 87
post4 challenge 28 104
Modbus - whats the maximum I can store in one register? 4 80
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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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