Solved

Strings Array

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

691 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