【问题标题】:I am pretty sure I am making a stupid mistake, but this code gives out an output that is just too long to read我很确定我犯了一个愚蠢的错误,但是这段代码给出的输出太长而无法阅读
【发布时间】:2019-09-07 05:35:21
【问题描述】:

我认为我在指针之间的某个地方搞砸了。 我不知道我是否应该将 Book* 更改为某些内容。

任何帮助将不胜感激。谢谢。

istream& operator >> (istream& is, Warehouse& warehouse){

    int counter = 0;
    Book* temp;
    Book* headNode;

    is >> headNode;
    while (!is.eof()){
        temp = headNode;
        is>> headNode;
        headNode.setNext(temp); 
        counter++;
    }
    warehouse.bookCount = counter; 
    warehouse.head = headNode;
    return is;
}

【问题讨论】:

    标签: c++ pointers linked-list operator-overloading


    【解决方案1】:

    问题 1

    is >> headNode;
    

    错了。从文件中读取指针没有意义。您发布的代码中有两行这样的行。

    问题 2

    while (!is.eof()){
    

    错了。见Why is iostream::eof inside a loop condition considered wrong?

    如果没有看到您尝试从中读取链接列表数据的文件的内容,我无法提出修复建议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-24
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多