C Help T Get System Time Print Screen Output File Code Whenever Try Display System Time Gi Q37089044

C++ Help: Can’t get system time to print to screen/outputfile.

Below is my code. Whenever I try to display the system time itonly gives me the memory address at which the c-string is located.Please fix and provide screenshot of output.

//class definition:

class Restaurant
{

public:
short int restaurantNum;
int idNum;
char* mealTime[20];

};

// int main():

int main()
{
std::ofstream outputFile;
outputFile.open(“information.txt”);
Restaurant *patron = new Restaurant;
time_t now = time(0);
char* timeOf = ctime(&now);
timeOf[20] = ”;
patron->mealTime[20] = timeOf;
std::cout << patron->mealTime;

outputFile << patron->mealTime;
}


Solution


Here is code:

#include <iostream>

#include <fstream>

#include <string.h>

#include <time.h>

using namespace std;

class Restaurant

{

public:

short int restaurantNum;

int idNum;

string mealTime;

};

int main()

{

ofstream outputFile;

outputFile.open(“information.txt”);

Restaurant *patron = new Restaurant;

time_t now = time(NULL);

string timeOf = ctime(&now);

patron->mealTime = timeOf;

cout << patron->mealTime;

outputFile << patron->mealTime;

}

information.txt:

information.txt × 1 Fri Apr 19 8:29:06 2019

Output:

Fri Apr 19 08:29:06 2019

information.txt

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.