answersLogoWhite

0


Best Answer

In short, you don't.

The strdate() function returns a formatted string that represents the current date. It is not intended that this result be used in a date calculation such as increment. The complexities of converting back to month day and year, and then dealing with the special rules of the Gregorian calender, along with leap years is unrealistic, given that there are library functions that will do this for you already. Try this...

#include <time.h>

#include <iostream>

using namespace std;

...

char cdate[9];

time_t tt = time(NULL) + 86400; // tomorrow

struct tm *tomorrow;

tomorrow = localtime (&tt);

strftime(cdate, 9, "%m/%d/%y", tomorrow);

cout << cdate << endl;

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

In short, you don't.

The strdate() function returns a formatted string that represents the current date. It is not intended that this result be used in a date calculation such as increment. The complexities of converting back to month day and year, and then dealing with the special rules of the Gregorian calender, along with leap years is unrealistic, given that there are library functions that will do this for you already. Try this...

#include <time.h>

#include <iostream>

using namespace std;

...

char cdate[9];

time_t tt = time(NULL);

struct tm *nextyear;

nextyear = localtime (&tt);

nextyear->tm_year ++; // increment year

if (nextyear->tm_mon 29) { // handle feb 29th

nextyear->tm_mon ++;

nextyear->tm_mday = 1;

}

strftime(cdate, 9, "%m/%d/%y", nextyear);

cout << cdate << endl;

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you increment date using strdate in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is x plus equals y is post increment or pre increment?

The '+=' operator behaves like a pre increment operator.


What is the meaning of plus plus in c?

++a (plus plus a) is pre-incrementing operator to aa=10;printf("%d",++a); /* it will print 11 as ++a increment first a by 1 then prints it */printf("%d",a++); /*it will printf 10 as it is post _ increment operator , it prints the value a first then increment it by 1 */


Why there is only 2 plus in c plus plus languagewhy not 3 or 4 plus?

I assume by 2 plus you really mean ++. This is the increment operator which is used to increment the operand. If placed before the operand, the operator evaluates the incremented operand (prefix increment). If placed after the operand, the operator evaluates the non-incremented operand (postfix increment). +++ and ++++ are meaningless but are assumed to mean incrementing an increment. If you wish to increment an increment, you must use the compound expression ++(++) or (++)++. Thus for the variable x, prefix incrementing twice would be achieved with ++(++x), while postfix incrementing twice would be achieved with (x++)++. You can also mix the two, such as ++(x++) or (++x)++, both of which would increment x twice but would evaluate the increment of x. If postfix increment is not a requirement, it would be much easier to use the compound expression x+=n, where n is the amount you wish to increment. This is the same as saying x=x+n.


What is the difference between n-- and --n in C plus plus statement?

If these expressions are stand-alone (not nested), then they do the same thing, ie increment 'n'.


Is 'k equals k plus 1' same as 'k plus equals 1' in Java?

Yes, they are exactly the same, both of them increment k in 1.

Related questions

How different is pre and post increment in c plus plus from pre and post increment in C programming?

The pre and post increment (and decrement) operator is the same in C++ as it is in C.


Is x plus equals y is post increment or pre increment?

The '+=' operator behaves like a pre increment operator.


What is the meaning of plus plus in c?

++a (plus plus a) is pre-incrementing operator to aa=10;printf("%d",++a); /* it will print 11 as ++a increment first a by 1 then prints it */printf("%d",a++); /*it will printf 10 as it is post _ increment operator , it prints the value a first then increment it by 1 */


Why there is only 2 plus in c plus plus languagewhy not 3 or 4 plus?

I assume by 2 plus you really mean ++. This is the increment operator which is used to increment the operand. If placed before the operand, the operator evaluates the incremented operand (prefix increment). If placed after the operand, the operator evaluates the non-incremented operand (postfix increment). +++ and ++++ are meaningless but are assumed to mean incrementing an increment. If you wish to increment an increment, you must use the compound expression ++(++) or (++)++. Thus for the variable x, prefix incrementing twice would be achieved with ++(++x), while postfix incrementing twice would be achieved with (x++)++. You can also mix the two, such as ++(x++) or (++x)++, both of which would increment x twice but would evaluate the increment of x. If postfix increment is not a requirement, it would be much easier to use the compound expression x+=n, where n is the amount you wish to increment. This is the same as saying x=x+n.


Why c plus plus name was given?

In C, the ++ operator means to increment the object associated with it. If you said xyz++; for instance, you would increment xyz. (There are pre-increment and post-increment forms, but that is out of scope for this question.) When the C language was enhanced, the new language was called C++, implying that C++ was the "next", or "incremented", version of C.


What is the difference between the statement a plus plus and plus plus a?

This is used in languages such as C, C++ and Java. The difference is when the statement is executed. If placed before the variable, the increment is done before other operations, otherwise, after them. This is best shown in an example.a + b++ means to add first, then to increment the variable b.a + ++b means to increment b first, then to do the addition.Similarly, in a = b++, b is copied to a, and then increment; while in a = ++b, variable b is incremented before being copied.


Is there a difference between you plus plus and plus plus you?

you++ will return the current value of you and increment it. ++you will increment it and then return the new value of you. So, for example: int you = 0; cout &lt;&lt; you++; // this will print 0 cout &lt;&lt; you; // this will print 1 int you = 0; cout &lt;&lt; ++you; // this will print 1 cout &lt;&lt; you; // this will also print 1


How what operator is most efficient you plus plus or plus plus you?

Efficiency is the same; the difference is when the "++" is evaluated, before or after other operations. For example: a = b++ // This will first copy b to a, then increment b. a = ++b // This will first increment b, then copy it to a. If you have the "++" operator by itself, it makes no different if you use prefix or postfix. a++ is the same as ++a.


What is the difference between n-- and --n in C plus plus statement?

If these expressions are stand-alone (not nested), then they do the same thing, ie increment 'n'.


Is 'k equals k plus 1' same as 'k plus equals 1' in Java?

Yes, they are exactly the same, both of them increment k in 1.


What is the Difference between post fix and prefix plus plus operator?

For both cases, the ++ operator increments the integer by one. The difference lies in when it makes that increment. Take the following for example: int B = 3 A = ++B // A = 4, B = 4 --------------- int B = 3 A = B++ //A = 3, B = 4 In the prefix example, the increment occurs before the assignment. In the suffix example, the increment occurs after the assignment.


Why are there 2 plus sign in c plus plus and Why not a single plus sign?

In C and in C++, the ++ operator means to increment. C++ was intended to be the next version, i.e. the incremental next step, of C, hence the use of the ++ operator.