小编And*_*all的帖子

通过string :: insert插入char时出错

我的问题与类似,但那里没有示例代码,我觉得它没有用.

我的错误是

调用类'std :: __ 1 :: __ wrap_iter'的私有构造函数

我的问题的一个最小例子可以在下面找到:

#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;
}
Run Code Online (Sandbox Code Playgroud)

我通过两个编译器尝试了这个,并且出现了同样的错误.从标准文档中尽可能多地阅读,但不理解我的错误.

c++ string

3
推荐指数
1
解决办法
42
查看次数

标签 统计

c++ ×1

string ×1