C++ vector de inicialización de pares
Tengo
vector< pair<int, int>> myVec (N);
Quiero tener todos los pares inicializados a -1,-1.
23
Author: MyNameIsKhan, 2012-06-19
2 answers
Aquí tienes:
#include <utility>
vector<pair<int, int>> myVec (N, std::make_pair(-1, -1));
El segundo argumento para ese constructor es el valor inicial que tomarán los N pares.
36
Author: mfontanini,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-24 14:58:49
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-07-24 14:58:49
Solo para agregar algo de información adicional (no exactamente lo que el Preguntador quería, pero pidió en los comentarios de la respuesta aceptada):
La inicialización individual se puede hacer con (C++11):
std::vector<std::pair<int, int> > vec1 = { {1, 0}, {2,0}, {3,1} };
std::vector<std::pair<int, int> > vec2 = {std::make_pair(1, 0),
std::make_pair(2, 0),
std::make_pair(3, 0)};
En los viejos estándares de C++, algo como esto funcionaría:
const std::pair<int,int> vals[3] = {std::make_pair(1, 0),
std::make_pair(2, 0),
std::make_pair(3, 0)};
std::vector<std::pair<int, int> > vec2 (&vals[0], &vals[0] + 3);
6
Author: DomTomCat,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-04 11:38:50
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-04 11:38:50