Solved

Strings Array

Posted on 1998-08-31
3
238 Views
Last Modified: 2010-04-02
What is the easiest way to create an array of strings when those strings have a variable length ? Should I use a 2 dimensional char array or  is it possible to create a 1 dimensional array of Cstring elements. Any sample code welcome.

Thanks,
Arnaud.
0
Comment
Question by:decornez
3 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 20 total points
ID: 1171799
You must be using MFC since you mentioned CString.

Simply use

CString astrName[7];

astrName[0] = _T("decornez");
astrName[1] = _T("array");
astrName[2] = _T("search");
//...

0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1171800
You may also like to consider the CArray class which will expand the array as needed (you don't have to allocate all the elements at the start).

This in <afxtempl.h> - add a #include to your stdafx.h

Then declare you're array

CArray< CString, CString& > array ;

array.Add( "Hello World" ) ; // adds to the array

CString strFirstItem = array[0] ; // retrieves first value
0
 

Author Comment

by:decornez
ID: 1171801
Sounds good.

Thanks to both of you for your help.

Arnaud.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

815 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now