Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #87736
| Path | csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: initial size of a std::vector of std::strings |
| Date | Wed, 07 Dec 2022 13:49:41 -0800 |
| Organization | None to speak of |
| Lines | 50 |
| Message-ID | <87edta6g0a.fsf@nosuchdomain.example.com> (permalink) |
| References | <tmp947$g0jv$1@dont-email.me> <tmptcb$hm5s$1@dont-email.me> <tmquhd$kuud$1@dont-email.me> |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | reader01.eternal-september.org; posting-host="e9284c35170f8649df9b0e58c7fb123c"; logging-data="697560"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XjXl3tKz4f3lxAOPm9Jb+" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
| Cancel-Lock | sha1:fNaozsrgwFESbefWBrq76oDraAE= sha1:yN9RwAStkk1+Xa8YtL3m9cMDfRk= |
| Xref | csiph.com comp.lang.c++:87736 |
Show key headers only | View raw
Lynn McGuire <lynnmcguire5@gmail.com> writes:
[...]
> I am trying to declare a vector with max_ncp strings in a struct.
> struct component_data {
> std::vector <std::string> component_names [max_ncp];
> doublereal heatoffusionatmeltingpoint [max_ncp];
> doublereal meltingpointtemperature [max_ncp];
> doublereal sublimationtemperature [max_ncp];
> doublereal triplepointtemperature [max_ncp];
> doublereal triplepointpressure [max_ncp];
> };
>
> Visual Studio 2015 does not like
> std::vector <std::string> component_names (max_ncp);
> or
> std::vector <std::string> component_names (max_ncp, "");
How does it express its dislike? Both work for me:
#include <vector>
#include <string>
#include <iostream>
int main() {
int max_ncp = 42;
{
std::vector<std::string> component_names(max_ncp);
std::cout << component_names.size() << ' ';
}
{
std::vector<std::string> component_names(max_ncp, "");
std::cout << component_names.size() << '\n';
}
}
The output is "42 42".
> But it does like
> std::vector <std::string> component_names [max_ncp];
> But it does not work.
That defines an array (not a std::array, just a C-style array object) of
max_ncp vectors. I think you want a single vector.
Do you want to set the initial size or the initial capacity?
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-06 23:42 -0600
Re: initial size of a std::vector of std::strings James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-12-07 00:52 -0500
Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 08:17 +0100
Re: initial size of a std::vector of std::strings Öö Tiib <ootiib@hot.ee> - 2022-12-07 00:23 -0800
Re: initial size of a std::vector of std::strings Juha Nieminen <nospam@thanks.invalid> - 2022-12-07 09:13 +0000
Re: initial size of a std::vector of std::strings Öö Tiib <ootiib@hot.ee> - 2022-12-07 06:03 -0800
Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 15:37 +0100
Re: initial size of a std::vector of std::strings Öö Tiib <ootiib@hot.ee> - 2022-12-07 09:33 -0800
Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 18:45 +0100
Re: initial size of a std::vector of std::strings Paavo Helde <eesnimi@osa.pri.ee> - 2022-12-07 16:34 +0200
Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 15:38 +0100
Re: initial size of a std::vector of std::strings Juha Nieminen <nospam@thanks.invalid> - 2022-12-08 07:58 +0000
Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 16:28 -0600
Re: initial size of a std::vector of std::strings Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-07 14:53 -0800
Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 16:56 -0600
Re: initial size of a std::vector of std::strings Juha Nieminen <nospam@thanks.invalid> - 2022-12-08 08:03 +0000
Re: initial size of a std::vector of std::strings "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-12-07 12:28 +0100
Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 14:54 -0600
Re: initial size of a std::vector of std::strings "daniel...@gmail.com" <danielaparker@gmail.com> - 2022-12-07 13:16 -0800
Re: initial size of a std::vector of std::strings "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-12-07 22:33 +0100
Re: initial size of a std::vector of std::strings Bonita Montero <Bonita.Montero@gmail.com> - 2022-12-07 22:37 +0100
Re: initial size of a std::vector of std::strings Michael S <already5chosen@yahoo.com> - 2022-12-07 13:34 -0800
Re: initial size of a std::vector of std::strings Bo Persson <bo@bo-persson.se> - 2022-12-07 23:48 +0100
Re: initial size of a std::vector of std::strings Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-07 13:49 -0800
Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 16:01 -0600
Re: initial size of a std::vector of std::strings Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-07 14:47 -0800
Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 17:09 -0600
Re: initial size of a std::vector of std::strings Bo Persson <bo@bo-persson.se> - 2022-12-07 23:45 +0100
Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-07 17:08 -0600
Re: initial size of a std::vector of std::strings Lynn McGuire <lynnmcguire5@gmail.com> - 2022-12-08 01:44 -0600
csiph-web