c++ - 如何将链表的内容写入文件

标签 c++ file-io std

我有一个写入函数,我用它来将列表的内容写入文件。该列表仅包含数字。

list<int>::iterator pos;
    for (pos = listStorage.begin(); pos != listStorage.end(); ++pos)
    {
        out << *pos << endl;
    }
    return out;

我在编译时遇到错误;

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::list<_Ty>::_Const_iterator<_Secure_validation>' (or there is no acceptable conversion)

有人可以帮忙吗?谢谢

最佳答案

我相当确定这是一个常量问题。您的 listStorage 对象是否声明为 const?如果是这样,您需要将迭代器声明为

const list<int>::iterator pos;

关于c++ - 如何将链表的内容写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5858920/

相关文章:

c++ - 有没有把header自动转换成cpp和hpp文件的工具?

c++ - 模板二元运算符不明确?

c++ - erase 获取 const_iterator 但使用迭代器调用(非 const)

C++11 线程队列

c++ - 解析 linux 内核文件 "Idle Service Error semantic-idle-summary-idle-function - Arithmetic error"时出现 cedet-语义错误 "jiffies.h"

c++ - opencv中多边形的亮度梯度?

java - 未报告的异常 java.io.IOException at actionlistener

Python:从列表创建字典并自动生成/增加键(列表是实际键值)?

javascript - 在本地保存使用 JavaScript 生成的加密文件

c++ - 如何将 Button_SetElevationRequiredState 与 QPushButton 一起使用?