473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Fun with strings and vectors

Hi,

I have quite a lot of strings that needs to go into a vector. Rather
than doing this:

std::vector<std::string> list; // not to be confused with std::list
list.push_back("a string");
list.push_back("another string");
list.push_back("arrgh, yet more strings");
list.push_back("my fingers are getting tired");

Is there a better way of doing this? Something like;

List myStrings[] = { "string 1", "string2", "string3" ... };

Thanks,
Alex
--
http://www.munted.org.uk

Take a nap, it saves lives.
May 10 '06 #1
4 1525
Alex Buell wrote:
Hi,

I have quite a lot of strings that needs to go into a vector. Rather
than doing this:

std::vector<std::string> list; // not to be confused with std::list
list.push_back("a string");
list.push_back("another string");
list.push_back("arrgh, yet more strings");
list.push_back("my fingers are getting tired");

Is there a better way of doing this? Something like;

List myStrings[] = { "string 1", "string2", "string3" ... };

See the 'what does this mean?' thread from a couple of hours ago.

--
Ian Collins.
May 10 '06 #2
On Tue, 09 May 2006 20:32:12 +1200, I waved a wand and this message
magically appeared from Ian Collins <ia******@hotmail.com>':
See the 'what does this mean?' thread from a couple of hours ago.


Damn. I must have missed that one; indeed yes that works perfectly and
the code doesn't suck! Thank you.

--
http://www.munted.org.uk

Take a nap, it saves lives.
May 10 '06 #3
Hi Alex,
Is there a better way of doing this? Something like;

List myStrings[] = { "string 1", "string2", "string3" ... };


....also take a look at the Boost Assignment Library...!

http://www.boost.org/libs/assign/doc/index.html

Best regards,
Tilman
May 10 '06 #4
On Tue, 9 May 2006 11:17:12 +0200, I waved a wand and this message
magically appeared from "Tilman Kuepper" <ti************@nexgo.de>':
Is there a better way of doing this? Something like;

List myStrings[] = { "string 1", "string2", "string3" ... };


...also take a look at the Boost Assignment Library...!

http://www.boost.org/libs/assign/doc/index.html


Oh well I guess it's a good time as any to take an indepth look at
Boost. Thanks.

--
http://www.munted.org.uk

Take a nap, it saves lives.
May 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Reginald Carlier | last post by:
Hi, I'm programming a game and one of the variables is a two dimensional array in wich I store the names of the players. So far so good; with cin.get I ask the names of the players and...
9
by: Rafi Kfir | last post by:
Hi, This may look as a smiple task to most of you, but to me (a beginner with C), it drives me crazy. All I want is that one function passes a two dimensional array of strings to another...
7
by: Ben | last post by:
Hey everybody, I'm working on a program in c++, and I've come up against a problem that I can't figure out. I don't imagine that it's too difficult to solve, but it has been giving me trouble....
3
by: Amit | last post by:
Hello. I am having some problem organizing a set of vectors. The vectors itself, could contain a pointer( say integer pointer) or could contain another object MyClass. 1>So, first of all, is...
4
by: panik | last post by:
Hi, I'm looking for something similar to Encryption. I'd like to generate URL's with a format that avoids visible ID's (e.g. http://thesite/viewlink.aspx?ID=105) Instead, I'd like to generate a...
30
by: zexpe | last post by:
I have an extremely cpu/data intensive piece of code that makes heavy use of the following function: void convertToDouble(const std::string& in, double& out) { out = atof(in.c_str()); } I...
8
by: LinuxDuud | last post by:
Hi, First, Sorry if the title was bad, I really didn't know how to describe this. So, What I need to do is something like this: char somevariable; // The tricky part. I don't know how to define...
4
by: CoreyWhite | last post by:
/* WORKING WITH STRINGS IN C++ IS THE BEST WAY TO LEARN THE LANGUAGE AND TRANSITION FROM C. C++ HAS MANY NEW FEATURES THAT WORK TOGETHER AND WHEN YOU SEE THEM DOING THE IMPOSSIBLE AND MAKING...
1
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...

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.