0

I am trying to read time for an assignment. I am using the following code. It was working fine earlier, but now gives an error:

#include <iostream>
#include <string>
#include <ctime>
#include <vector>
#include <sstream>

using namespace std;

#define LOG(x) cout << x << endl

class Date
{
private:
    string date;
    string time;
    string day;
    string month;
    string year;
    string WeekylQuote;

public:
    void TimeReadFromSystem(string &str) //this function read time of system
    {
        time_t my_time = time(NULL);
        
    }

    void StorerOfAscTimeIntoVariables(const string &str)
    {
        vector<string> strTok;
        istringstream ss(str);
        string deliminiters;
        while (ss >> deliminiters)
        {
            strTok.push_back(deliminiters);
        }
        //for (auto i : strTok)
        //cout << i << endl;
        //OUTPUT
        //Thu
        //Apr
        //22
        //00:46:59
        //2021

        // storing now day month year in respective variables
        date = (strTok[2]);
        month = (strTok[1]);
        year = (strTok[4]);
        time = (strTok[3]);
        day = (strTok[0]);
    }
};

The error occurs on time(NULL):

type 'std::string' (aka 'basic_string') does not provide a call operator

I have also noticed if I create another .cpp and just implement that function, it seems to work, but in the code I have written for my assignment it doesn't work.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 5
    You have a member variable called `time`, it shadows `time()` function from global scope. Call it as `std::time(NULL);` or rename your variable to something else. – Yksisarvinen Apr 22 '21 at 17:27
  • 2
    Relevant: [Why is `using namespace std;` considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Ted Lyngmo Apr 22 '21 at 17:34

0 Answers0