|
I have that "LBS_HASSSTRINGS" actually just stepping thru the code on ClistBox::AddString the VS debugger
comes up with a DialogBox "BreakPoint hit" a message indicating some sort of exception
I am wondering if I cannt do AddString in OnitDialog for a OwneDraw litbox ?
|
|
|
|
|
Calling AddString() itself should not raise an exception (provided that the list box window exists) because that just sends the LB_ADDSTRING message. I guess it is happening later when other list box operations are performed.
|
|
|
|
|
I made a custom DDX to create the list box
DDX_TextVAL(pDX, IDC_STORAGE_AREAS, storage_area);
HWND tempwin = ::GetDlgItem(pDX->m_pDlgWnd->m_hWnd, nIDC);
LPTSTR temptr = (LPTSTR)new char[10];
::GetClassName(tempwin, temptr, 10);
if (strcmp((char *)temptr, "Edit") == 0)
value.Attach(pDX->PrepareEditCtrl(nIDC));
else
value.Attach(pDX->PrepareCtrl(nIDC));
delete temptr;
CListBox storage_area
|
|
|
|
|
ForNow wrote: I made a custom DDX to create the list box
And what for?
IMHO, it is not a good idea...
|
|
|
|
|
|
When I step thru the debugger on ClistBox::AddString it (VS debugger) just says breakpoint hit seems like for OwnerDraw I cann't do addstring in OinitDialog
Notsure
|
|
|
|
|
With that little information it's anyone's guess what is going on. I have used AddString in the OnInitDialog method, in normal and owner drawn list boxes.
|
|
|
|
|
Ok thanks that’s helpful I’ll do some digging
|
|
|
|
|
Consider the following code
"main.cpp"
#include <stdio.h>
#include "../include/ESSolver.h"
int mu;
int lambda ;
int main(void)
{
mu = 5;
lambda = 10;
ESSolver es;
es.Init();
es.Optimize();
return 0;
}
"ESSolver.h"
extern int mu;
extern int lambda ;
class ESSolver
{
public:
const static int nVar = 4;
ESSolver();
~ESSolver(void);
void Init();
void Optimize();
int rand_r(int, int);
private:
double (*muPop)[nVar];
double *muSigma;
double (*lambdaPop)[nVar];
double *lambdaSigma;
double (*mulambdaPop)[nVar];
double *mulambdaSigma;
};
"ESSolver.cpp"
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include "../include/ESSolver.h"
using namespace std;
ESSolver::ESSolver()
{
double _muPop [mu][nVar];
muPop = _muPop;
muSigma = new double[mu];
double _lambdaPop [lambda][nVar];
lambdaPop = _lambdaPop;
lambdaSigma = new double[lambda];
double _mulambdaPop [mu+lambda][nVar];
mulambdaPop = _mulambdaPop;
mulambdaSigma = new double[mu+lambda];
return;
}
ESSolver::~ESSolver(void)
{
if (muSigma) delete muSigma;
if (lambdaSigma) delete lambdaSigma;
if (mulambdaSigma) delete mulambdaSigma;
return;
}
void ESSolver::Init()
{
for (int i = 0; i < mu; i++)
{
for (int j = 0; j < nVar; j++)
{
muPop[i][j] = 50;
}
}
cout << "\n----- muPop -----\n";
for (int i = 0; i < mu; i++)
{
for (int j = 0; j < nVar; j++)
{
cout << muPop[i][j] << " ";
}
cout << endl;
}
}
void ESSolver::Optimize()
{
cout << "\n----- muPop -----\n";
for (int i = 0; i < mu; i++)
{
for (int j = 0; j < nVar; j++)
{
cout << muPop[i][j] << " ";
}
cout << endl;
}
}
On running the following code I am getting Output
[^]
As you can see from the image, Matrix is not getting initialized. Can anybody tell me why.
modified 29-Jan-21 21:01pm.
|
|
|
|
|
Quote: double _muPop [mu][nVar];
muPop = _muPop;
_mPop is a temporary array (a local variable), your muPop pointer is goingo to point to garbage.
|
|
|
|
|
Thanks
modified 29-Jan-21 21:01pm.
|
|
|
|
|
|
How can we find the index of smallest 3 elements in an array. Below code finds the index of largest 3 elements in an array.
#include <vector>
#include <iostream>
using namespace std;
int main()
{
double arr[] = {0.2, 1.0, 0.01, 3.0, 0.002, -1.0, -20};
priority_queue < pair<double, int> > pQueue;
for (int i = 0; i < 7; i++)
{
pQueue.push(pair<double, int>(arr[i], i));
}
int k = 3;
for (int i = 0; i < k; ++i)
{
int ki = pQueue.top().second;
cout << ki << " ";
pQueue.pop();
}
}
modified 29-Jan-21 21:01pm.
|
|
|
|
|
See std::priority_queue - cppreference.com[^]:
Quote: A user-provided Compare can be supplied to change the ordering, e.g. using std::greater<t> would cause the smallest element to appear as the top(). Another solution would be inverting the sign of the items pushed into the queue:
pQueue.push(pair<double, int>(-arr[i], i));
|
|
|
|
|
Where should I put
std::greater<t>
in the code.
modified 29-Jan-21 21:01pm.
|
|
|
|
|
See the link from my answer. It contains example code showing that it must be passed as 3rd template parameter. So you have to pass also the 2nd parameter.
As with any templates, T (uppercase) is a placeholder for the corresponding type which is std::pair<double, int> in your case.
So it must be (untested):
priority_queue < pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>> > pQueue;
|
|
|
|
|
Thanks it worked
modified 29-Jan-21 21:01pm.
|
|
|
|
|
Hi,
I have a value float a=1234.5578
I want to print output as 1234.55.
How to approach this ?
|
|
|
|
|
Read up on printf formatting. Google will find you lots of tutorials and references.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Are you sure you want 1234.55 as output? The number would be rounded to 1234.56.
|
|
|
|
|
Unless you are going to be programming large scale complex mathematical problems you should stay well clear of floating point numbers. There are quite a few issues to be understood which can catch you out. And given this and the question below, your time would be better spent getting hold of a good C++ study guide. Trying to learn by posting questions here will take you far too much time.
|
|
|
|
|
Try here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi,
I am a newbee to c++.
iostream include definition of cout and cin
But if I write cout without std, It throws error, which should be corrcted to std::cout.
Why so?
|
|
|
|
|
In order to have insight on <iostream > content, feel free to check out the documentation: <iostream> - C++ Reference[^].
std is the namespace[^] of the C++ Standard Library , quoting Wikipedia[^]: "Features of the C++ Standard Library are declared within the std namespace".
In order to use <iostream> objects, e.g. cout you need either to
or
modified 29-Nov-17 6:44am.
|
|
|
|
|
Hi,
But how the std and cout is related?
|
|
|
|