通过字符串::插入插入字符时出错
error when inserting a char via string::insert
我的问题与此类似,但那里没有示例代码,而且我觉得它没有帮助。
我的错误是
调用类的私有构造函数 '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;
}
我已经通过两个编译器和相同的错误尝试了这个。 尽可能多地阅读标准文档,但不了解我的错误。
最好检查 std::string::insert(( 重载的所有签名,然后决定使用哪一个。g.insert(0,temp);
只是与它们中的任何一个都不匹配。
对于插入char
,您可以传递一个迭代器,例如
g.insert(g.begin(), temp);
或者传递索引并一起计数:
g.insert(0, 1, temp);
相关文章:
- 从人员矢量插入和读取文件时出错
- unordered_map在分配或插入时出错
- 在 C/C++ 中使用 MySQL 连接器执行插入到表时出错
- 通过字符串::插入插入字符时出错
- Sqlite 插入时出错
- 在二维德劳奈三角测量中插入顶点时出错
- 在二叉搜索树C++中插入字符串时出错
- 当我尝试将一对插入地图时,Qt程序seg出错
- stl:map插入值时出错
- 在 unordered_map Boost 中插入模板值时出错
- 插入AVL树时出错
- 插入字符串时出错<<过载C++
- 插入 Set C++ 时出错
- 在二进制树中插入数据时出错
- 将单词插入链表时出错
- 在链表的开头插入时读取内存时出错
- 使用向量C++在 sqlite3 中插入记录时出错
- C++:在集合中插入结构时出错
- 为什么在尝试将新节点插入列表时出错
- 在unordered_map中插入字符串键和值时出错