|
hi all,
how to get difference between two dates using CDateTimeCtrl ?
venu
|
|
|
|
|
Simple - extract the date / time from the control CDateTimeCtrl::GetTime (...) . You would then have a CTime , SYSTEMTIME , or even a COleDataTime .
CTime has comparison functions you can use.
Iain.
|
|
|
|
|
Put the two times in a COleDateTime object, and get the difference via COleDateTimeSpan .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi everyone,
I'm attempting to write a program that takes command line arguments, reads data in from a file,
and then appropriately searches for certain data or sorts the data for output based on the argument passed.
I am having trouble figuring out how to actually sort the vectors according to the attributes.
the struct is as follows:
<br />
struct Wizard<br />
{<br />
string FirstName;<br />
string LastName;<br />
int Grade;<br />
double WandWeight;<br />
};<br />
The datafile being read from simply has each property separated by a single whitespace character. The vector is declared simply as:
<br />
vector(Wizard) wizVec;<br />
(NOTE: angle braces would not show up in preview, assume they take the place of the round braces in the vector declaration)
Don't ask about the name of the struct, it's my prof's example!
Any suggestions or solutions are appreciated and needed!
Thanks in advance!
|
|
|
|
|
To get < and > to show, you need to check 'Ignore HTML tags' below.
You can write a function object that compares two Wizard objects, and pass that into the sort algorithm.
Here[^] is an article on the subject.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Use std::sort to sort the vector. Add an operator < for your struct to define the sort order or code a predicate function or functor and pass it to std::sort .
Steve
|
|
|
|
|
Thanks for the article Christian, and the suggestion, Stephen. I will try to follow the instructions in the article. I appreciate the help, and the speedy replies
Does this logic make sense in context?
void SortVecAscending(vector<Wizard> &wizVector, string prop)
{
// Sort vector smallest to largest, according to prop(erty)
bool compare_Wizards(const Wizard& a, const Wizard& b)
{
return a.prop < b.prop;
}
std::sort(wizVector.begin(), wizVector.end(), compare_Wizards);
}
|
|
|
|
|
Yes, that looks like it should work.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
C++ does not support local functions (functions in functions). You can have functors in function however.
Steve
|
|
|
|
|
C++ does not support local functions (functions in functions). You can have functors in function however.
Steve
|
|
|
|
|
Thanks again for all your help, gentlemen. I got the sorting working with no more problems.
However, now that I have moved on to the searching portion, I find that the way the project is designed,
I have to search for values in the structs that are NOT strings.
To refresh your memory:
struct Wizard
{
string FirstName;
string LastName;
int Grade;
double WandWeight;
};
Is there any viable way to convert a string to an int, a string to a double, or vice versa?
I have attempted to use static_cast<string>() on the int and double values, and static_cast<int>() / static_cast<double>() on the string values, but the compiler didn't like those conversions.
I have looked around, and there is nothing available to me without downloading someone's class and using it. Since this is a school project, I have a feeling that would be frowned upon.
Any ideas?
If any clarification is needed, simply ask.
|
|
|
|
|
There are multiple ways, here's one:
#include "StdAfx.h"
#include <iostream>
#include <string>
#include <sstream>
int main()
{
using namespace std;
string s = "1234";
int num;
istringstream ss(s);
ss >> num;
if (ss)
{
cout << "Number is " << num << endl;
}
return 0;
}
And another:
#include "StdAfx.h"
#include <iostream>
#include <string>
#include <cstdlib>
int main()
{
using namespace std;
string s = "1234";
int num = atoi(s.c_str());
cout << "Number is " << num << endl;
return 0;
}
The second method is easier but error handling is more difficult as if no valid conversion could be performed, a zero value is returned. Also, in the first version simply changing the type of the num variable will make the code work different types but the second version requires a distinct function for each type: atoi only works for int s.
Steve
|
|
|
|
|
Thanks again!
I ended up using the stringstream approach, as our prof is fanatical about us not using "pure" C functions.
You guys are life savers!
Regards,
Bryan
|
|
|
|
|
Your professor is a wise man.
Steve
|
|
|
|
|
|
Thanks for the info, Mike!
I'm a codeproject n00b, but I get the newsletter!
|
|
|
|
|
What are these 'lparam' and 'wparam' ? Where can i get info abt these?
Consider:
BOOL PostMessage(
UINT message,
WPARAM wParam = 0,
LPARAM lParam = 0
);
MSDN says
The content of 'lparam' and 'wparam' parameter depends on the message being posted.
What will be the values when mouse is clicked or key is pressed?
Thanks in Advance.
|
|
|
|
|
LameThought wrote: What are these 'lparam' and 'wparam' ?
They are message-specific values. Some messages use one, the other, both, or neither.
LameThought wrote: Where can i get info abt these?
MSDN, CP, Google.
LameThought wrote: What will be the values when mouse is clicked or key is pressed?
Again, it all depends on the specific message you are inquiring about.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Now, i want to Set Focus for Edit Box in Dialog using PostMessage, then what will be the values of both?
|
|
|
|
|
Use the SetFocus() function for this.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
In a dialog, use WM_NEXTDLGCTRL which automagically handles the subtleties in how dialogs handle focus. More from Raymond: Clickety[^]
|
|
|
|
|
You should use SetFocus API in this case as David said earlier.
If you see documentation for WM_SETFOCUS , it will tell you, what should be values passed, as wParam and lParam .
It applies to all windows messages.
|
|
|
|
|
I think you will find WPARAM is a WORD and LPARAM is a long. MSDN is right, they are generic parameters, what they mean changes according to what the message is. MSDN will tell you what they mean in each instance, you just need to find the help for the message you're after.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: I think you will find WPARAM is a WORD and LPARAM is a long.
And I thought I was old
WPARAM and LPARAM are both pointer size these days - UINT_PTR and LONG_PTR, respectively.
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
where con i find example vc++ programs so that i can learn multithreading
|
|
|
|