调用vector的size()
时出现此编译器错误。为什么?错误C2228:'.size'的左边必须有class/struct/union
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cassert>
using namespace std;
class Vertex {
float firstValue;
float secondValue;
float thirdValue;
Vertex (float first, float second, float third){
firstValue=first;
secondValue=second;
thirdValue=third;
}
};
int main()
{
cout<<"This program loads a 3D .off object. \nEnter the name of the file that describes it "<<endl;
string inputFileName;
getline(cin, inputFileName);
ifstream inputFileStream;
inputFileStream.open(inputFileName.data());
assert (inputFileStream.is_open());
string actualLine;
for(;;){
inputFileStream>>actualLine;
istringstream actualLineStream(actualLine);
std::vector<float> results(std::istream_iterator<int>(actualLineStream)
, std::istream_iterator<int>());
int resultsIndex=0;
int resultsSize=results.size(); //WHY??
while (resultsIndex<resultsSize){
cout<<results[resultsIndex]<<endl;
}
if (inputFileStream.eof()) break;
}
ofstream outputChannel;
while (true){} // to keep on console view
return 0;
}
哇..我从来没有想过这一点。 – andandandand 2010-11-14 03:24:58
我很高兴找到这篇文章。这种行为是可怕的。 – 2011-04-21 09:59:24
是的,感谢上帝,我发现了这一点。我准备把我的笔记本电脑扔出窗外。 – MikeTheLiar 2012-10-22 23:57:55