How to insert the English alphabet into a vector in C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
 
using std::cout;
using std::endl;
using std::vector;
 
int main()
{
    vector<char> vec;
 
    for (int i = 0; i < 26; i += 1) 
        vec.push_back('A' + i);
     
    copy(vec.cbegin(), vec.cend(), std::ostream_iterator<char>(cout, " "));
 
    cout << endl;
}
 
 
/*
run:
 
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 
 
*/

 



answered Mar 1, 2018 by avibootz
edited Oct 19, 2024 by avibootz

Related questions

1 answer 118 views
4 answers 301 views
3 answers 185 views
3 answers 187 views
...