sort alphabetically

Hello. All I need is to sort letters alphabetically. Program scans a row of capital latin letters. I do not know, what is best to create: an array, a string or a vector. But I need to sort these letters in alphabetic order. What is best way to dot it? You can write any of your ideas, thanks.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
    std::string row;
    std::getline(std::cin, row);
    std::sort(row.begin(), row.end());
    std::cout << row;
}
AROWOFLETTERS
AEEFLOORRSTTW
Thank you. And another one question: how to sort specific letters, ex: range [4; 7]? it is: WOFL to FLOW (from your example). Other letters keep untouched.
1
2
3
4
//Indexes start with 0, end iterator points to _after_ last character to sort
std::sort(row.begin() + 3, row.begin() + 7); 
//or
std::sort(&row[3], &row[7]);
AROFLOWETTERS
Topic archived. No new replies allowed.