|
The most obvious flaw I can see is that your are interverting loop test and variable increment in your for loops.
The syntax is
for (init; condition; increment) , and you are using
for (init; increment; condition) instead.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
Well spotted, but I would expect his app to crash if that is in the actual running system.
|
|
|
|
|
Yes, very well spotted ... I wrote the sample code too quickly
|
|
|
|
|
I also wonder why these loops are needed, since you do not even use nNumRow and nNumCol in the loops. What is the relation of the loop variables nNumRow and nNumCol to the ar variable?
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
It is no wonder we are getting confused if you are not even showing the actual code that has the problem.
|
|
|
|
|
Thank you all for your help.
The example code is very close to the actual code and the problem is that sometimes, depending on the computer, because of the operator >> to deserialize the style m_pFont, several m_pFont pointed to the same memory area.
I studied the problem with a minimal grid ... and finally realized that in my application I was not using this m_pFont. I modified my code so that I would no longer use it at all, destroy it and set it to NULL which definitively resolved my problem.
If I don't fully explain the phenomenon, I think it comes from the fact that these m_pFont contained the same data and that the operators << consider the pointer had already been serialized as explained in the TN002: Persistent Object Data Format | Microsoft Docs ... Maybe ...
Regards
|
|
|
|
|
Any Thing To Send Data To Crystal Report By VC++ 6.0
,We Can Say , PrintOut Method
Object : Change No Copies Dynamic Through Code
|
|
|
|
|
Other application can print out without problem ? Have tried to print to another printer ? Or, have you tried to run that command on another machine ? You can find more if you do some debugging on your code ...
modified 24-May-20 2:43am.
|
|
|
|
|
I used the below code for creating CEdit dynamically, code compiled but editbox is not visible on screen
[CODE]
CEdit *tedit = new CEdit:
tedit->CreateEx(WS_EX_CLIENTEDGE , L"Edit", L" ", ES_AUTOHSCROLL | ES_LEFT | WS_BORDER | WS_VISIBLE | WS_CHILD ,this,IDC_EDIT);
[/CODE]
|
|
|
|
|
You need to provide more details of your code. That line should work according to the documentation. There must be something else that needs to be done.
|
|
|
|
|
|
<l>I am trying to learn c++ programming language and am still an amateur at it. I have a problem with "passing arrays in a function" and all am asking is what would be the easiest way to handle this problem?
|
|
|
|
|
Here is a thread[^] that should answer your question, and then some.
|
|
|
|
|
Greg Utas wrote: and then some Should that be "and then lots"?
|
|
|
|
|
Be aware that the standard C++ library gently offers many alternative containers[^] to arrays.
|
|
|
|
|
and are extremely useful, though sometimes performance is mystifying
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
The right container for the right job...
|
|
|
|
|
*sometimes*. And it may very well depend on the platform.
I have a communications system that transmits data using tags and a parser. I have upwards of 500 data elements that can go back and forth. The initial implementation used a simple linear search for finding a passed tag. As time passed, the tag set became larger and larger.
Hey, this is a good place for a mapped data set, allowing me to find the tag quickly I thought. The map turned out to be 3 times slower than the linear search. Never did figure out why. Showed the sample code to someone who loves the STL and has a lot more experience than I do. No idea. Someday I'll get back to it.
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
My little experiment gives me opposite results:
#include <iostream>
#include <map>
using namespace std;
constexpr int Indices = 4096;
constexpr int Size = 512;
extern const int idx[Indices];
extern const string tag [Size];
int linear_search(const string & s )
{
for (int n = 0; n<Size; ++n)
if ( s == tag[n]) return n;
return -1;
}
constexpr int Iterations = 1000000;
int main()
{
std::map<string, int> mtag;
for (int n=0; n<Size; ++n)
{
mtag.insert(make_pair(tag[n], n));
}
int sum = 0;
for (int n=0; n<Iterations; ++n)
{
int i = idx[n % Indices];
const string & s = tag[i];
int k;
#ifdef LINEAR_SEARCH
k = linear_search( s );
#else
auto it = mtag.find(s);
k = it->second;
#endif
sum+=k;
}
cout << "sum " << sum << endl;
} Where
tag is an array of 512 randomly generated strings (having length betwween 4 and 12)idx is an array of 4096 randomly generated indices (for quickly gatering a candidate)
Output
g++ -D LINEAR_SEARCH -Wall lookup.cpp -o lookup_linear_search
g++ -Wall lookup.cpp -o lookup_map
time ./lookup_linear_search
sum 252632422
real 0m1,821s
user 0m1,811s
sys 0m0,008s
time ./lookup_map
sum 252632422
real 0m0,297s
user 0m0,297s
sys 0m0,000s
|
|
|
|
|
Hmm, your code is surprising close to mine.
What compiler are you using? I have to use VS2008 for embedded work, so maybe the STL implementation is suspect. I'll have to dust it off. Your results are what I would have expected.
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Quote: What compiler are you using? The good one.
The hint is in the command line[^]:
g++ -D LINEAR_SEARCH -Wall lookup.cpp -o lookup_linear_search
|
|
|
|
|
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
how do you incorporate the GUI in C++?
|
|
|
|
|
You can use the standard Win32 controls, or if your are writing MFC code, then there are classes for every situation.
|
|
|
|
|
And if you are on Linux, then you probably want to look at gtk or QT. I'm not sure what Mac uses these days.
There's dozens of tool-kits available for Linux and Windows, many are cross-platform, too. Use google to find something you like, and suits your needs.
Keep Calm and Carry On
|
|
|
|