Vb.net had a variable call date so how to work at vc++ .If i provide a date i want to count the totaldayofthemonth.I had try used some software translation vb.net class to c# class fail.And i have problem trying to convert string to int and int to string
The code
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
#include "time.h"
#include <sstream>
// this file is is similiar with <iostream.h>
#using <mscorlib.dll>
using namespace System;
using namespace std;
class dateX {
private :
std::string changeZero(std::string dateInfo);
public :
std::string fowardDay (std::string date,std::string type);
public:
std::string prevDay(std::string date,std::string type);
};
std::string dateX::changeZero(std::string dateInfo) {
int dateLength;
dateLength = dateInfo.length();
if (dateLength = 1) {
std::ostringstream combine;
combine<<"0"<<dateInfo;
dateInfo= combine.str();
}
return (dateInfo);
}
std::string dateX::fowardDay(std::string date,std::string type){
std::string dayInt=date.substr(6,2);
std::string monthInt=date.substr(4,2);
std::string yearInt=date.substr(0,4);
std::string returnDate;
std::string dayStr;
std::string monthStr;
std::string yearStr;
std::ostringstream combine;
//int totalDayInMonth=date('t',mktime('','','',month,day,year));
// how to to above code
// betul echo $this->totalDayInMonth;
if(type=="day") {
if(dayInt >= totalDayInMonth){
dayInt=1;
if(monthInt==12) {
yearInt++;
monthInt=1;
}
else {
monthInt++;
}
}
else { dayInt++; }
dayStr=dateX::changeZero(dayInt);
monthStr=dateX::changeZero(monthInt);
combine<<yearStr<<monthStr<<dayStr;
returnDate== combine.str();
}
else if (type=="month") {
if(monthInt==12) {
yearInt++;
monthInt=1;
}
else {
monthInt++;
//echo $this->month;
}
monthStr=dateX::changeZero(monthInt);
combine<<yearStr<<monthStr<<dayStr;
returnDate== combine.str();
}
else if(type=="year") {
yearInt++;
yearStr=yearInt;
combine<<yearStr<<monthStr<<dayStr;
returnDate== combine.str();
}
return (returnDate);
}
void _tmain()
{
}

date
Neville Clayton
I'm not sure about managed C++, either. In plain C++ you'd just say DateTime dt; and you'd have one.
cyclops
R.Nargang
i got the answer maybe next day i will published the code still testing the class.My lec in poli saz she don't see lot of contructor in c++ but my code a lot hehe
SPaula
#using <mscorlib.dll>
mscorlib.dll means you're using managed C++, which means you can use the DateTime class, just as you would in VB.NET or C#. Apart from this, C++ as a language has no native support for dates as a concept, and there are a number of Microsoft specific date formats, none as friendly to use as DateTime.
atoi converts strings to int, if you need to do that for any reason.
digitizer143
i still got problem on converting string to int i try to used int.parse(string)fail i also try using some method using sstring whatever still fail.Below are the code any idea plesase.....
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
// this is similiar to <iostream.h> file header
#include <sstream>
// this file is used to acces .net framework
#using <mscorlib.dll>
// when using is was to access class of system and class of std of .net framework
using namespace System;
using namespace std;
//declaration of class
class dateX {
private :
std::string changeZero(std::string dateInfo);
public :
std::string fowardDay (std::string date,std::string type);
public:
std::string prevDay(std::string date,std::string type);
int public convertStringToInt(string strSource);
};
// convert string to integer
int dateX::convertStringToInt(std::string strSource)
{
int test;
return test.Parse("strSource");
}
// here to convert 0 till 9
std::string dateX::changeZero(std::string dateInfo) {
int dateLength;
dateLength = dateInfo.length();
if (dateLength = 1) {
std::ostringstream combine;
combine<<"0"<<dateInfo;
dateInfo= combine.str();
}
return (dateInfo);
}
std::string dateX::fowardDay(std::string date,std::string type){
int dayInt=dateX::convertStringToInt(date.substr(6,2));
int monthInt=dateX::convertStringToInt(date.substr(4,2));
int yearInt=dateX::convertStringToInt(date.substr(4,2));
std::string returnDate;
std::string dayStr;
std::string monthStr;
std::string yearStr;
int totalDayInMonth=System::DateTime::DaysInMonth(yearInt,monthInt);
// betul echo $this->totalDayInMonth;
if(type=="day") {
if(dayInt >= totalDayInMonth){
dayInt=1;
if(monthInt==12) {
yearInt++;
monthInt=1;
}
else {
monthInt++;
}
}
else { dayInt++; }
dayStr=dateX::changeZero("dayInt");
monthStr=dateX::changeZero("monthInt");
returnDate=yearStr+monthStr+dayStr;
}
else if (type=="month") {
if(monthInt==12) {
yearInt++;
monthInt=1;
}
else {
monthInt++;
//echo $this->month;
}
monthStr=dateX::changeZero("monthStr");
returnDate=yearStr+monthStr+dayStr;
}
else if(type=="year") {
yearInt++;
dateX::convertStringToInt("yearInt");
returnDate=yearStr+monthStr+dayStr;
}
return (returnDate);
}
std::string dateX::prevDay(std::string date,std::string type) {
int dayInt=dateX::convertStringToInt(date.substr(6,2));
int monthInt=dateX::convertStringToInt(date.substr(4,2));
int yearInt=dateX::convertStringToInt(date.substr(4,2));
std::string returnDate;
std::string dayStr;
std::string monthStr;
std::string yearStr;
int totalDayInMonth=System::DateTime::DaysInMonth(yearInt,monthInt);
if(type=="day") {
dayInt=dayInt--;
dayStr=dateX::changeZero("dayInt");
if(dayInt == 0 ) {
// i don't know sometimes calculation on variable-- not work
monthInt--;
monthStr=dateX::changeZero(monthStr);
dayInt=totalDayInMonth;
if(monthInt ==0) {
// since december is 31 no waste to count
dayInt=31;
yearInt--;
monthInt=12;
}
}
returnDate=yearStr+monthStr+dayStr;
}
else if(type=="month") {
monthInt--;
if(monthInt==0) {
monthInt=12;
yearInt--;
}
monthStr=dateX::changeZero(monthStr);
returnDate=yearStr+monthStr+dayStr;
}
else if(type=="year") {
yearInt--;
returnDate=yearStr+monthStr+dayStr;
}
return (returnDate);
}
void _tmain()
{
dateX dateX;
dateX.fowardDay("20050501","day");
}