Hi everyone. I have a bit confusion about vector.
here is my 2 structs <global>and in the main have vector declared.
file name is"report.txt"
Have file with meteo readings,like 
•   
the meteorologist’s name on duty that day (a string of up to 12     characters)

•   hours of sunshine (double)

•   rainfall in millimeters (double)

•   midday temperature in degrees (double)

looks like 12 1 2009 tommy 3.4 12.5 9.5 
  ...... so on for a full month.
  The question is how do i copy file contents into vector for a use.
  Here what i have :
  struct DATE{
    int day;
    int month;
    int year;


   };
struct onDutyRecords{
    string name;
    double sunshine;
    double rainfall;
    double midTemp;
    DATE date;

             };



 int _tmain(int argc, _TCHAR* argv[])
   {
    vector<onDutyRecords>records;

    return 0;
    }        

Recommended Answers

All 2 Replies

Ok. Put a space between the '>' and 'records' on line 38. Other than that, what is your problem other than confusion? Show how you are using the vector.

To insert the struct you can use the vector method push_back.

#include <iostream>
#include <vector>
#include <string>

struct DATE
{
    int day;
    int month;
    int year;
};

struct onDutyRecords
{
    std::string name;
    double sunshine;
    double rainfall;
    double midTemp;
    DATE date;
};


int main()
{
    std::vector<onDutyRecords> records;

    DATE today;
    today.day = 19;
    today.month = 9;
    today.year = 2014;

    onDutyRecords record;
    record.name = "me";
    record.sunshine = 1;
    record.rainfall = 2;
    record.midTemp = 3;
    record.date = today;

    records.push_back(record);

    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.