468,484 Members | 1,762 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

std::string array

2
Hi there,
I am wondering that can a class member be an array of string. I can create an 2d array of char but I really want to use an array of std::string. Can any body help me out?

NB: This is my first time posting any thread in any forum. I am not sure that I could explain my question. Please ask me if you need further details.
Feb 28 '08 #1
3 4254
Laharl
849 Expert 512MB
You can create a 2D array of strings, sure. If you have one of chars already, just replace char with string in the declaration. There is an issue with dynamic allocation and default constructors (you'd better supply one if you don't use {entry, entry} notation) since the arguments can't be passed to the constructor. Also, before weaknessforcats gets in here, read this howto on arrays in C/C++.

Expand|Select|Wrap|Line Numbers
  1. string mat[3][4];
  2.  
Feb 28 '08 #2
SKSNET
2
Thanx a lot for your help.

You can create a 2D array of strings, sure. If you have one of chars already, just replace char with string in the declaration. There is an issue with dynamic allocation and default constructors (you'd better supply one if you don't use {entry, entry} notation) since the arguments can't be passed to the constructor. Also, before weaknessforcats gets in here, read this howto on arrays in C/C++.

Expand|Select|Wrap|Line Numbers
  1. string mat[3][4];
  2.  
Mar 1 '08 #3
weaknessforcats
9,207 Expert Mod 8TB
You create an array of strings by using a vector.

Expand|Select|Wrap|Line Numbers
  1. vector<string> arr;
  2.  
A vector is implemented as a array. The vector member functions are the same functions you would need to write to use your C++ array. Why do the work over again?
Mar 1 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

19 posts views Thread by Espen Ruud Schultz | last post: by
19 posts views Thread by Erik Wikström | last post: by
8 posts views Thread by Jason Heyes | last post: by
7 posts views Thread by JustSomeGuy | last post: by
10 posts views Thread by sposes | last post: by
84 posts views Thread by Peter Olcott | last post: by
4 posts views Thread by daroman | last post: by
4 posts views Thread by barnum | last post: by
7 posts views Thread by Hendrik Schober | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.