473,504 Members | 13,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string arrays?

36 New Member
I was thinking about this, and I decided to ask...

Is it acceptable in the C++ world to make an array out of a string object?

Example:
Expand|Select|Wrap|Line Numbers
  1. std::string str[50];
  2.  
Now, before the answers start flowing, let me state: I am NOT planning on doing this.

I recently learned how to use vectors, so I would use a string vector before I would do the above.

I know it's possible to do ( I've done it ), but I've been wondering if it was "ok" do this.

It's not that important, I just thought, maybe someone out there uses this in their programs.


Thanks for your time!

-Soneji
Jun 21 '07 #1
4 1176
ilikepython
844 Recognized Expert Contributor
I was thinking about this, and I decided to ask...

Is it acceptable in the C++ world to make an array out of a string object?

Example:
Expand|Select|Wrap|Line Numbers
  1. std::string str[50];
  2.  
Now, before the answers start flowing, let me state: I am NOT planning on doing this.

I recently learned how to use vectors, so I would use a string vector before I would do the above.

I know it's possible to do ( I've done it ), but I've been wondering if it was "ok" do this.

It's not that important, I just thought, maybe someone out there uses this in their programs.


Thanks for your time!

-Soneji
I think it's Ok. I use it sometimes. It's the same thing as "char * str[50];". But I'm sure someone else can give a more technical reason.
Jun 21 '07 #2
ljfong
1 New Member
I was thinking about this, and I decided to ask...

Is it acceptable in the C++ world to make an array out of a string object?

Example:
Expand|Select|Wrap|Line Numbers
  1. std::string str[50];
  2.  
Now, before the answers start flowing, let me state: I am NOT planning on doing this.

I recently learned how to use vectors, so I would use a string vector before I would do the above.

I know it's possible to do ( I've done it ), but I've been wondering if it was "ok" do this.

It's not that important, I just thought, maybe someone out there uses this in their programs.


Thanks for your time!

-Soneji
It's ok if for some reason you have to dispense with the overheads that come with vectors. Vectors are basically "enhanced" version of arrays, with better type safety, better memory management, better bound checking, and so on. When memory and/or space is at absolute premium, such as coding for embedded devices, I would imagine you would dispense even with std::string, preferring to do with straight char*, or char** for array of strings.
Jun 21 '07 #3
plemoine
15 New Member
std::vector is higly recommended (see Scott Meyer books - Effective C++ / Effective STL).
Expand|Select|Wrap|Line Numbers
  1. using namespace std;
  2.  
  3. vector<string> strVec;
  4. strVec.reserve(50);
  5. strVec.push_back(". . .");
  6. strVec.push_back(". . .");
  7.  
I was thinking about this, and I decided to ask...

Is it acceptable in the C++ world to make an array out of a string object?

Example:
Expand|Select|Wrap|Line Numbers
  1. std::string str[50];
  2.  
Now, before the answers start flowing, let me state: I am NOT planning on doing this.

I recently learned how to use vectors, so I would use a string vector before I would do the above.

I know it's possible to do ( I've done it ), but I've been wondering if it was "ok" do this.

It's not that important, I just thought, maybe someone out there uses this in their programs.


Thanks for your time!

-Soneji
Jun 22 '07 #4
Soneji
36 New Member
Thanks for the answers guys ( and/or girls ) :)

I appreciate you taking the time to respond.

I'm out, Lates!

-Soneji
Jun 22 '07 #5

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

Similar topics

3
4831
by: Java script Dude | last post by:
Some programmers prefer to stay with native level data structures such as string arrays instead of using Object based data structures such as ArrayList. From and efficiency point of view. Are...
16
17352
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
4
8777
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
17
4635
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
37
3765
by: jortizclaver | last post by:
Hi, I'm about to develop a new framework for my corporative applications and my first decision point is what kind of strings to use: std::string or classical C char*. Performance in my system...
18
1659
by: greenflame | last post by:
I want to make a function that does the following. I will call it thefunc for short. '||Char>>' I tried the following def thefunc(s): s = "||" + s + ">>"
14
12148
by: rohitpatel9999 | last post by:
Hi While developing any software, developer need to think about it's possible enhancement for international usage and considering UNICODE. I have read many nice articles/items in advanced C++...
9
2081
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
3
2177
by: SneakyElf | last post by:
i am very green with c++ so i get stuck on very simple things anyway, i need to write a program that would read data from file (containing names of tv shows and their networks) one line at a time...
3
2220
by: shapper | last post by:
Hello, I have two arrays of strings, s1 and s2: s1 = "london, lisbon, paris, newyork" s2 = "lisbon, yellow, France" s2 will have only one item included in s1.
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.