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:
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
4 1176
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:
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.
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:
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.
std::vector is higly recommended (see Scott Meyer books - Effective C++ / Effective STL). -
using namespace std;
-
-
vector<string> strVec;
-
strVec.reserve(50);
-
strVec.push_back(". . .");
-
strVec.push_back(". . .");
-
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:
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
Thanks for the answers guys ( and/or girls ) :)
I appreciate you taking the time to respond.
I'm out, Lates!
-Soneji
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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 *...
|
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...
|
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...
|
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...
| |
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 + ">>"
|
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++...
|
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,...
|
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...
|
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.
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |