Thread: Reading from file into a struct using a customer Vector class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    6

    Reading from file into a struct using a customer Vector class

    Hi, so I'm fairly new to structs, and what I want to do is read data from a file into a struct. My struct uses 2 classes date and time to read in date and time values, and I've created a Custom Vector class that stores this information in a dynamic array and expands when it needs to.

    I'm strugging how to figure out how to read the data into my struct, and for now I am using a test file to test functionality. I'm getting some errors.

    Main.cpp:
    Code:
    #include <iostream>
    #include <fstream>
    #include "Date.h"
    #include "Time.h"
    #include "Vector.h"
    
    
    using namespace std;
    
    
    typedef struct {
    
    
            Date d;
            Time t;
            float speed;
    
    
    }WindLogType;
    
    
    int main()
    {
    
    
    Date dTest;
    Time tTest;
    float speedtest = 52.5;
    
    
    Vector<WindLogType> windlog;
    
    
    ifstream infile("testinput.csv");
    
    
    if(!infile){
    
    
        cout << "File not found.";
    
    
        return -1;
    
    
    };
    
    
    //int i = 0;
    
    
    while(!infile.eof()){
    
    
        infile >> dTest >> tTest >> speedtest;
    
    
        windlog.add(dTest); //line 42 for error
        windlog.add(tTest); //line 43 for error
        windlog.add(speedtest); //line 44 for error
    
    
    }
    
    
    for(int i = 0; i < windlog.size(); i++){
    
    
        cout << windlog[i] << " "; //line 50 for error
    
    
    }
    
    
    
    
    infile.close();
    
    
    return 0;
    
    
    }



    Errors:
    Code:
    Line |42|error: no matching function for call to 'Vector<WindLogType>::add(Date&)'|
    
    Line |43|error: no matching function for call to 'Vector<WindLogType>::add(Time&)'|
    
    Line |44|error: no matching function for call to 'Vector<WindLogType>::add(float&)'|
    
    |50|error: cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&'|
    Inputfile:
    31/2/2014 23:45,55.6
    My Vector add method handles any type of data because I've used it in previous exercises so I think the issue lies in how I'm using my struct. Somebody please help!
    Last edited by daffer; 05-02-2020 at 04:09 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a text file to a vector
    By satty in forum C++ Programming
    Replies: 8
    Last Post: 01-19-2011, 08:18 AM
  2. Reading from a vector to a file
    By veronicak5678 in forum C++ Programming
    Replies: 5
    Last Post: 04-10-2008, 12:57 AM
  3. Class/Struct in a Vector...
    By yaya in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2008, 04:16 AM
  4. vector - left of .push_back must have class/struct/union type
    By patricio2626 in forum C++ Programming
    Replies: 5
    Last Post: 11-18-2006, 04:37 PM
  5. reading a customer record file
    By abbycat131 in forum C++ Programming
    Replies: 1
    Last Post: 01-29-2003, 09:15 PM

Tags for this Thread