Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #68209
| From | Ralf Goertz <me@myprovider.invalid> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Initialization of std::vector<std::string> throws |
| Date | 2019-09-04 14:09 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <qko9ig$97d$1@dont-email.me> (permalink) |
Hi,
why does the declaration
std::vector<std::string> pt({{"One","Two"}});
throw:
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_M_create
whereas neither
std::vector<std::string> pt({{"One"}});
nor
std::vector<int> pt({{1,2}});
does? Full program:
#include <vector>
#include <string>
#include <iostream>
std::vector<std::string> pt({{"One","Two"}});
int main() {
for (auto p:pt) std::cout<<p<<std::endl;
}
No warning is given during compilation by gcc version 9.2.1 20190820
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
Initialization of std::vector<std::string> throws Ralf Goertz <me@myprovider.invalid> - 2019-09-04 14:09 +0200
Re: Initialization of std::vector<std::string> throws Sam <sam@email-scan.com> - 2019-09-04 08:20 -0400
Re: Initialization of std::vector<std::string> throws Ralf Goertz <me@myprovider.invalid> - 2019-09-04 14:33 +0200
Re: Initialization of std::vector<std::string> throws Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2019-09-05 23:26 -0400
Re: Initialization of std::vector<std::string> throws Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-09-18 08:37 -0700
Re: Initialization of std::vector<std::string> throws Ralf Goertz <me@myprovider.invalid> - 2019-11-22 12:12 +0100
Re: Initialization of std::vector<std::string> throws Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2019-11-22 13:44 +0000
Re: Initialization of std::vector<std::string> throws Ralf Goertz <me@myprovider.invalid> - 2019-11-22 16:03 +0100
Re: Initialization of std::vector<std::string> throws Bo Persson <bo@bo-persson.se> - 2019-11-22 16:22 +0100
Re: Initialization of std::vector<std::string> throws Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2019-11-22 16:13 +0000
Re: Initialization of std::vector<std::string> throws "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-11-22 16:30 +0100
Re: Initialization of std::vector<std::string> throws Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-04 14:43 +0200
csiph-web