error when inserting a char via string::insert

Viewed 110

My question is similar to this one but there is no sample code there, and I didn't find it helpful.

My error is

calling a private constructor of class 'std::__1::__wrap_iter'

A minimal example of my problem can be found below:

#include <iostream>
#include <string>

using namespace std;

int main(){
    string g = "this_word";
    cout << g << endl;
    char temp = g[0];
    g.erase(0,1);
    cout << g << endl;
    g.insert(0,temp); // Compiler seems to dislike this.  Why?
    cout << g << endl;
    return 0;
}

I've tried this through two compilers, and the same error. Read as much as I could from the standard documentation, but don't understand my error.

1 Answers
Related