重用istream_iterator变量

时间:2015-06-19 19:01:29

标签: c++ c++11

我使用两个迭代器从文本文件读取到vector

std::ifstream input_file("~/blahblah.txt");
std::istream_iterator<float> start(input_file),end;
std::vector<float> testFrameFloat(start,end);
input_file.close();input_file.clear();

然后,我使用相同的ifstream来读取另一个文本文件。是否可以重用相同的istream_iterators而不是创建新的input_file.open("~/anothertext.txt"); start(input_file); //this is a compilation error std::vector<float> readValues(start,end); ?如果我尝试这样做,我会收到编译错误:

JButton pieceToMoveButton = null;   //variable that persists between actionPerformed calls

public void actionPerformed(ActionEvent actionEvent)
{
    JButton button = (JButton)actionEvent.getSource();

    if (pieceToMoveButton == null)    //if this button press is selecting the piece to move
    {
        //save the button used in piece selection for later use
        pieceToMoveButton = button;
    }
    else        //if this button press is selecting where to move
    {
        //move the image to the new button (the one just pressed)
        button.imageIcon = pieceToMoveButton.imageIcon
        pieceToMoveButton = null;    //makes the next button press a piece selection
    }
}

0 个答案:

没有答案