我正在尝试读取作业时间。我正在使用以下代码。之前工作正常,但现在出现错误:
#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]);
}
};
错误发生在 time(NULL)
:
type 'std::string' (aka 'basic_string') 不提供调用运算符
我还注意到,如果我创建另一个 .cpp
并仅实现该函数,它似乎可以工作,但在我为我的作业编写的代码中它不起作用。