back_inserter() and string
This won't work in VC++6:
Code:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
const int size = 3;
char myArray[size] = {'y', 'e', 's'};
string str;
copy(myArray, myArray + size, back_inserter(str));
cout<<str<<endl;
return 0;
};
I get the error:
Quote:
error C2039: 'push_back' : is not a member of 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
c:\program files\c++microsoft visual studio\vc98\include\iterator(82) : while compiling class-template member function 'class std::back_insert_iterator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >
&__thiscall std::back_insert_iterator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::operator =(const char &)'
Error executing cl.exe.
back_inserter() calls push_back() for the container, and the string class has a push_back() member function, so is that a compiler bug, or am I doing something wrong?