There is a program parsing csv file:

#include <iostream> #include <ctime> #include <vector> #include <string> #include <sstream> #include <fstream> struct JournalEntry { tm time; std::vector<std::string> data; }; int main() { std::ifstream file("file.csv"); std::vector<JournalEntry> journal; std::string buf; //skip 1st line std::string rawLine; std::getline(file, rawLine); while (std::getline(file, rawLine)) { JournalEntry je; std::stringstream ss(rawLine); while (std::getline(ss, buf, ',')) { je.data.push_back(buf); } journal.push_back(je); } std::cout << journal.size() << std::endl; std::cout << journal.data.size() << std::endl; return 0; } 

Everything parses well and fits into the structure, but when I call journal.data.size() , I get a C2228 compilation error (the expression to the left of .size should represent a class, structure, or union) . I can not understand what causes this error.

It seems that I have something close to this problem, but still the reason is not very clear.

    1 answer 1

    journal is a vector, and in journal.data.size (), you apparently go to the element of the vector, not the vector. You need to specify the index of the element of the vector, like this:

     std::cout << journal[0].data.size() << std::endl; 
    • Ah ah ah. Overlooked ... Shame. - kekyc