?
Solved

Strings Array

Posted on 1998-08-31
3
Medium Priority
?
241 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 80 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.
Suggested Courses

762 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