我试图从文本文件中的单独行中读取未知数量的双精度值到名为
rainfall
的向量中。我的代码无法编译,我得到了错误信息no match for 'operator>>' in 'inputFile >> rainfall'
在while循环行中。我知道如何将文件读入数组,但是我们需要在此项目中使用向量,而我还不太懂它。我很感谢您在下面的部分代码上给出的任何提示。vector<double> rainfall; // a vector to hold rainfall data
// open file
ifstream inputFile("/home/shared/data4.txt");
// test file open
if (inputFile) {
int count = 0; // count number of items in the file
// read the elements in the file into a vector
while ( inputFile >> rainfall ) {
rainfall.push_back(count);
++count;
}
// close the file