Solved

Strings Array

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 learn how to clear a vector as well as how to detect empty vectors in C++.

706 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

17 Experts available now in Live!

Get 1:1 Help Now