Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- using namespace std;
- int main(){
- int longitud_arreglo; //Esta variables almacenar la cantidad de elementos que va a tener nuestro array
- cout << "Cuantos nombres desea ingresar ? "; // le pido al usuario que ingrese el numero de nombre que va a ingresar
- cin>>longitud_arreglo;
- string nombre[longitud_arreglo]; // aqui creamo un array de tipo string que tendra el numeros elementos que el valor que tenga longitud_arreglo
- for(int i =0; i<longitud_arreglo; i++){
- cout << "El ingrese el nombre numero " << i <<" : " << endl;
- cin >> nombre[i];
- }
- vector<string>lista_de_nombres(nombre , nombre+longitud_arreglo);
- sort(lista_de_nombres.begin(), lista_de_nombres.end()); // aqui es que ordenamos los vectores
- cout << "nombres ordenados en orden alfabetico " << endl;
- //primera opcion para mostrar los vectores
- for(vector<string>::iterator it = lista_de_nombres.begin(); it != lista_de_nombres.end(); it++ ){
- cout << *it << endl;
- }
- //si quieres mostrar mas rapido haz esto
- /*
- for(int i =0; i<longitud_arreglo; i++){
- cout << lista_de_nombres [i] << endl;
- }
- */
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement