希望有人可以提供帮助,因为我迷路了。当我之前运行我的程序时,它工作正常,现在由于某种原因我得到错误消息
致命错误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;
}
非常感谢任何帮助,对于长篇文章感到抱歉。
答案 0 :(得分:1)
你搞砸了评论:
// 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"
答案 1 :(得分:0)
您是否已查看过&#34; TimeClass.h&#34;?我曾见过类似的错误,它起源于.h文件。
我知道这应该是一个评论,但没有足够的声明:(