472,779 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

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 4545
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,208 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

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

Similar topics

19
by: Espen Ruud Schultz | last post by:
Lets say I have a char pointer and an std::string. Is it possible to get a pointer to the std::string's "content" so that the char pointer can point to the same text? And vice versa; can I give...
24
by: Julie | last post by:
I'm re-evaluating the way that I convert from a std::string to char *. (Requirement: the source is a std::string, the usable contents are char *) Here is what I've come up with: #include...
19
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not...
8
by: Jason Heyes | last post by:
If s is a std::string, does &s refer to the contiguous block of characters representing s?
7
by: JustSomeGuy | last post by:
I need to make a class called uid. A UID is a unique identifier. It looks like... 1.2.3.345.1.2.4.566 This uid get transmitted over a network as 8 bit binary data. If the length of the UID is...
10
by: sposes | last post by:
Im very much a newbie but perhaps somehone can help me. Ive been searching for a way to convert a std::string to a unsigned char* The situation is I have a function that wants a unsigned char*...
84
by: Peter Olcott | last post by:
Is there anyway of doing this besides making my own string from scratch? union AnyType { std::string String; double Number; };
4
by: daroman | last post by:
Hi Guys, i've problem with my small C++ programm. I've just small template class which represetns a array, everything works fine up to combination with std::string. I did tried it with M$ VC++ and...
4
by: barnum | last post by:
Hi, I have a std::string which I know is UTF-8 encoded. How can I make a System::String^ from it? I tried UTF8Encoding class, but it wants a Byte array, and I don't know how to get that from a...
7
by: Hendrik Schober | last post by:
Hi, this #include <string> class test { typedef std::string::size_type size_type; static const size_type x = std::string::npos; }; doesn't compile using either VC9 ("expected constant...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.