Thanks guys for the input however I ran into some problems.
JLBorges- "warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\time.inl(112) : see declaration of 'localtime'" is the message I got. It says build is successful but I dont see it creating a new file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <ctime>
#include <string>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <time.h>
#include <fstream>
int main ()
{
std::time_t rawtime ;
std::time ( &rawtime ) ;
const std::tm* timeinfo = std::localtime ( &rawtime ) ;
char yyyymmdd[16] ;
std::strftime( yyyymmdd, sizeof(yyyymmdd), "%Y%m%d", timeinfo ) ;
const std::string path_suffix = "Reconciliation.csv" ;
const std::string file_name = yyyymmdd + path_suffix ;
std::ifstream inData(file_name);
inData.close();
return 0;
}
|
Stewbond- Below is the error i received: error C2628: 'date' followed by 'int' is illegal (did you forget a ';'?)
error C3874: return type of 'main' should be 'int' instead of 'date'
error C2664: 'date::date(const date &)' : cannot convert parameter 1 from 'int' to 'const date &'
1> Reason: cannot convert from 'int' to 'const date'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <ctime>
#include <string>
#include <sstream>
#include <iomanip>
#include <fstream>
class date
{
public:
date::date(int m, int d, int y) : _d(d), _m(m), _y(y) {} // CTOR with initialization lists
std::string str()
{
std::stringstream iss; //We'll use a stringstream to concatinate the dates
iss << std::setw(4) << std::setfill('0') << _y; //setw() and setfill('0') ensure leading zeros are there.
iss << std::setw(2) << std::setfill('0') << _m << _d;
return iss.str(); //Now we just return the string present in iss.
}
private:
int _d, _m, _y;
}
int main()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
int day = timeinfo->tm_mday;
int month = timeinfo->tm_mon+1;
int year = timeinfo->tm_year+1900;
date newDate(month,day,year);
std::string DateStamp = newDate.str();
std::string filename = DateStamp + "reconciliation" + ".csv";
std::ifstream inData(filename);
inData.close();
return 0;
}
|