Solved

Strings Array

Posted on 1998-08-31
3
239 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
[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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

726 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