Hello programmers!

I have been working on STL algorithms for some time now as a beginner, and I started doing an exercise, among which is the task of use the fill algorithm to fill the entire array of strings named items with "hello". My code for this is below:

//  Various statements in exercise in using STL Algorithms

#include <iostream>
#include <algorithm>
#include <iterator>
#include <array>
using namespace std;

int main()
{
    //various statements in using STL algorithms
    ostream_iterator<int> output(cout," ");             //iterator

    const size_t SIZE=10;
    array<string,SIZE> myStrings;                       //array of empty strings
    fill(myStrings.begin(),myStrings.end(),"hello");    //using the fill algorithm to fill the entire array of strings with "hello"
    cout << "myStrings array of size " << myStrings.size() << " after the fill algorithm is:\n";
    copy(myStrings.cbegin(),myStrings.cend(),output);
}

However, when I compile on my xCode compiler, I get the following error message (for the algorithm.h file): "No viable overloaded '='. Here's the area in the algorithm file where the problem is shown (I am just copying and pasting here):

template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
    for (; __first != __last; ++__first, ++__result) //THE ERROR is here, with the part "__first != __last"
        *__result = *__first;
    return __result;
}

I did not alter a single thing in the algorithm file (or any other imported file that is part of the C++ package), so as far as I know, it should be error free.

I did some investigating, and when I remove all references to the ostream_iterator output, including the initializing and the final line with the copy algorithm, the error goes away, and the compiler compiles successfully.

I tried searching on the internet, and I could not find anything, so this is my last resort. Could someone help me understand why the algorithm file is malfunctioning?

What types were provided with the error? That is usually a good place to start looking. operator= is not defined for some pair of operands you are providing.

What do you mean: what types were provided with the error? The operator= is supposed to be working inside the algorithm file that is built into C++.

Since you are dealing with strings shouldn't ostream_iterator<int> output(cout," "); be ostream_iterator<string> output(cout," ");?

This question has already been answered. Start a new discussion instead.