Tôi nhận được lỗi trình biên dịch này khi gọi số size()
của vectơ. Tại sao?lỗi C2228: bên trái '.size' phải có lớp/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;
}
Wow .. Tôi sẽ không bao giờ nghĩ về điều đó. – andandandand
Tôi rất vui vì tôi đã tìm thấy bài đăng này. Hành vi này thật khủng khiếp. –
Vâng, cảm ơn Chúa tôi đã tìm thấy điều này. Tôi đã sẵn sàng để ném máy tính xách tay của tôi ra ngoài cửa sổ. – MikeTheLiar