Jun 17, 2016 at 3:58am UTC
I've put together a little program that uses a "Date" object to store and print a date in various ways. From what I can see, everything looks in order in my three folders, but when ran I receive 98 errors coming from various files. I began with an empty, win32 project application and have only used these three files. Below I have my header, implementation, and a simple driver. Below these are the build output and list of "outside" files the errors are marked from.
/////////////////////HEADER
#ifndef Date_H
#define Date_H
class Date
{
private:
int day;
int month;
int year;
public:
//constructors
Date(int, int, int);
Date();
//member functions
void printDig();
void printUS();
void printEU();
}
#endif
/////////////////////IMPLEMENTATION
#include "Date.h"
#include <string>
#include <iostream>
using namespace std;
Date::Date(int day, int month, int year)
{
if ((month < 1 || month > 12) || (day < 1 || (month == 1,3,5,7,8,10,12 && day > 31) || (month == 4,6,9,11 && day > 30) || (month == 2 && day > 28) ))
{ Date();
}
else
{ this-> month = month;
this-> day = day;
this-> year = year;
}
}
Date::Date()
{
this-> month = 1;
this-> day = 1;
this-> year = 2001;
}
void Date::printDig()
{
cout << month << "/" << day << "/" << year << endl;
}
void Date::printUS()
{
string months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September","October", "November", "December"};
cout << months[month] << ", " << day << ", " << year << endl;
}
void Date::printEU()
{
string months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September","October", "November", "December"};
cout << day << ", " << months[month] << year << endl;
}
//////////////////////////DRIVER
#include "Date.h"
#include <string>
using namespace std;
int main()
{
string months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September","October", "November", "December"};
Date validDate(26, 7,1997);
validDate.printDig();
validDate.printUS();
validDate.printEU();
Date invalid1(31, 4, 1636);
invalid1.printDig();
invalid1.printUS();
invalid1.printEU();
return 0;
}
////////////////////////BUILD OUTPUT
1>------ Build started: Project: Date Object, Configuration: Debug Win32 ------
1> Date Imp.cpp
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2367): error C2143: syntax error : missing ';' before 'string'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2367): error C2059: syntax error : 'string'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2367): error C2143: syntax error : missing ';' before '{'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2367): error C2447: '{' : missing function header (old-style formal list?)
1> Date Driver.cpp
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2367): error C2143: syntax error : missing ';' before 'string'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2367): error C2059: syntax error : 'string'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2367): error C2143: syntax error : missing ';' before '{'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2367): error C2447: '{' : missing function header (old-style formal list?)
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
//////////////ERRORS
sal.h
stdio.h
vadefs.h
crtdefs.h
ConcurrencySal.h
limits
iosfwd
string
stddef.h
stdlib.h
swprintf.inl
wchar.h