Попробуйте и положитесь на стандартную библиотеку, чтобы сделать тяжелую работу за вас, то, что вы пишете, действительно C с std::cout
и не поощряется.
#include <vector>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
std::vector<std::string> > heroes {
"Captain America", "Thor", "Wolverine", "Cyclops",
"Goliath", "Beast", "Angel", "Colossus", "Hulk",
"Quicksilver", "Ironman"
};
std::sort(heroes.begin(), heroes.end());
std::copy(heroes.begin(), heroes.end(),
std::ostream_iterator<std::string>(std::cout, ", "));
return 0;
}
Обратите внимание: если у вас нет C ++ 11, вам нужно будет добавить элементы в вектор вручную, используя:
std::vector<std::string> > heroes;
heroes.push_back("Captain America");
...