预编译标头有问题?

Issues with precompiled headers?

本文关键字:有问题 编译      更新时间:2023-10-16

希望有人能帮忙,因为我迷路了。 早些时候运行我的程序时,它工作正常,现在由于某种原因我收到错误消息

致命错误 C1010:查找预编译标头时文件意外结束。您是否忘记将"#include"stdafx.h"添加到您的源中?

我确实包括标题。目标是创建一个程序,该程序可以打印时间和日期,并能够输入窗口的大小以及具有两个不同文件的字体和背景颜色。第一个文件如下所示。

#include "TimeClass.h"
////////////////////////////////////////////////////////////////////////////
// Class to help with the usage of time.
//////////////////////////////////////////////////////////////////////////
CTimeClass::CTimeClass()
{
// Notice that the time is stored whenever this time object is created. 
// Use this to your advantage in "main".
// "m_st" holds the time and date information.
GetLocalTime(&m_st);
}
////////////////////////////////////////////////////////////////////////
CTimeClass::~CTimeClass()
{
// Empty - Nothing to destroy here.
}
short CTimeClass::Year()
{
// Place your code here to return the year as a short.
ConsoleTime ct;
short year = ct.wYear;
return year;
}
///////////////////////////////////////////////////////////////////////////
string CTimeClass::Month()
{
ConsoleTime ct; 
int month = cm.wMonth;
if (month == 0)
return "January";
else if (month == 1)
return "February";
else if (month == 2)
return "March";
else if (month == 3)
return "April";
else if (month == 4)
return "May";
else if (month == 5)
return "June";
else if (month == 6)
return "July";
else if (month == 7)
return "August";
else if (month == 8)
return "September";
else if (month == 9)
return "October";
else if (month == 10)
return "November";
else if (month == 11)
return "December";
else
return "error";
// Place your code here to return the month as a string.
}
//////////////////////////////////////////////////////////////
short CTimeClass::Day()
{
ConsoleTime ct;
short day = ct.wDay;
return day;
// Place your code here to return the day as a short.
}
//////////////////////////////////////////////////////////////////////
string CTimeClass::DayOfWeek()
{
ConsoleTime ct;
int day == st.wDayOfWeek;
if (day == 0)
return "Sunday";
else if (day == 1)
return "Monday";
else if (day == 2)
return "Tuesday";
else if (day == 3)
return "Wednesday";
else if (day == 4)
return "Thursday";
else if (day == 5)
return "Friday";
else if (day == 6)
return "Saturday";
else
return "error";
// Place your code here to return the day of the week as a string.
}
//////////////////////////////////////////////////////////////////
short CTimeClass::Hour()
{
ConsoleTime ct;
short hour = ct.wHour;
return hour;
// Place your code here to return the hour as a short.
}
///////////////////////////////////////////////////////////////////////////
short CTimeClass::Minute()
{
ConsoleTime ct; 
short minute = ct.wMinute;
return minute;
// Place your code here to return the minute as a short.
}
///////////////////////////////////////////////////////////////////////////
short CTimeClass::Second()
{
ConsoleTime ct;
short second = ct.wSecond;
return second;
// Place your code here to return the second as a short.
}

下面是我的第二个文件。

// ConsoleWindowClock.cpp : Defines the entry point for the console 
application.
//
#include "stdafx.h"
#include "ConsoleClass.h"
#include "TimeClass.h"
#include <iomanip>
#include <iostream>
#include <windows.h>
#include <stdlib.h>
using namespace std;

int main()
{
int width;
int height;
int fontsize;
int text;
int background;
int userclass;
int time;
userclass.ConsoleColor(text, background);
userclass.ConsoleWindowSize(width, height);
userclass.FontSize(fontsize);
cout << "This is the console window clock" << endl;
cout << "Please enter the window size in characters: " << endl;
cin >> width;
cin >> height;
cout << "Please enter the font size: " << endl;
cin >> fontsize;
cout << "Enter the Text color (0=Red, 1=Green, 2=Blue, -1=Random): " << 
endl;
cin >> text;
cout << "Enter the background color (0=Red, 1=Green, 2=Blue, -1=Random): " 
<< endl;
cin >> background;

while (true) 
{
cout << "The time is: " << time.Hour() << ":" << time.Minute() << ":" << 
time.Second() << endl;
cout << "The day of the week is: " << time.DayOfWeek() << endl;
cout << "The month, day, and year are: " << time.Month() << " " << 
time.Day() << ", " << time.Year() << endl;
Sleep(1000);
}

return 0;
}

任何帮助将不胜感激,对不起,长篇大论。

你搞砸了评论:

// ConsoleWindowClock.cpp : Defines the entry point for the console 
application.
//

应该是

// ConsoleWindowClock.cpp : Defines the entry point for the console 
// application.

此外,您应该在第一个文件中TimeClass.h之前包含预编译标头。

#include "stdafx.h"
#include "TimeClass.h"

你看过你的"TimeClass.h"吗?我看到了源自.h文件的类似错误。

我知道这应该在评论中,但没有足够的声誉:(