|
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
|
|
|
|
|
See here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The best place to start is here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
|
Dear frineds i ve created an exe project in MFC. now my problem is how to hide the dialog box during runtime?
is there anyway to do that? if so pls let me know.
thanks(in anticipation)
Malini Nair
|
|
|
|
|
this->ShowWindow(SW_HIDE);
|
|
|
|
|
Hi,
Does anyone knowes how can I obtain the virtual memory size of the process I'm running in?
Thanks,
|
|
|
|