How to insert an array of strings into a vector in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
 
int main()
{
    std::string arr[] = {"c++", "c", "c#", "java", "python", "php"};
    
    int len = sizeof(arr)/sizeof(arr[0]);

    std::vector<std::string> v(arr, arr + len);

    for (const auto &str : v) 
        std::cout << str << "\n";        

    return 0;
}
 
 
 
 
 
/*
run:
 
c++
c
c#
java
python
php

*/

 



answered Sep 19, 2021 by avibootz

Related questions

...