|
|
jon_80 wrote: That's what I've been told ma'am
Luc is not a female name!
Best Wishes,
-David Delaune
|
|
|
|
|
His post did not help much anyway
Jon
|
|
|
|
|
In general I recommend you study and solve the first error message first, so when asking about some questions you should make sure to include the first error message or other symptom. That will make it easier on everyone.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
You forgot using namespace std;
|
|
|
|
|
Any idea why this code doesn't compile?
<pre>
// SieveOfErathostenes.cpp : main project file.
#include "stdafx.h"
#include <bitset>
#include <iostream>
#include <ctime>
using namespace System;
int main(array<System::String ^> ^args)
{
const int N = 2000000;
clock_t cstart = clock();
bitset<N + 1> b;
int count = 0;
int i;
for (i = 2; i <= N; i++)
b.set(i);
i = 2;
while (i * i <= N)
{
if (b.test(i))
{
count++;
int k = 2 * i;
while (k <= N)
{
b.reset(k);
k += i;
}
}
i++;
}
while (i <= N)
{
if (b.test(i)) count++;
i++;
}
clock_t cend = clock();
double millis = 1000.0 * (cend - cstart) / CLOCKS_PER_SEC;
cout << count << " primes \n" << millis << " milliseconds\n";
return 0;
}
</pre>
Errors:
Error 4 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 5 error C2228: left of '.set' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 19 SieveOfErathostenes
Error 6 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 7 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 24 SieveOfErathostenes
Error 8 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 9 error C2228: left of '.reset' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 30 SieveOfErathostenes
Error 10 error C2065: 'b' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 11 error C2228: left of '.test' must have class/struct/union c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 39 SieveOfErathostenes
Error 12 error C2065: 'cout' : undeclared identifier c:\Users\Administrator\Documents\Visual Studio 2008\Projects\SieveOfErathostenes\SieveOfErathostenes\SieveOfErathostenes.cpp 46 SieveOfErathostenes
NOTE:
1. Core Java Vol I 8th Ed. Pg. 713 (727)
Jon
|
|
|
|
|
You forgot a using namespace std; You need this for iostream and bitset .
Dybs
|
|
|
|
|
Any know how to resize a column in datagrid
This is my code:
/////////////////////////////////////////////
dad = new OdbcDataAdapter("select * from MesgDetails", cn);
ds->Clear();
dad->Fill(ds);
dataGrid1->PreferredColumnWidth = 82;
dataGrid1->DataSource = ds->Tables->Item[0];
//////////////////////////////////////////////
i want to resize a specific column.
|
|
|
|
|
Hi,
I am kind of new to CLI, and I am unsure how to run an application on a remote PC from a local PC. I am looking for a way to do this via command line on windows. The idea is:
I need something similar to the services control 'sc'. But instead of controlling services remotely, I would like to run files on a PC in the network. I have found some custom applications to do this, but I would rather write my own batch scripts. Surely if they can write apps to do it, then there must be some way.
I think taskkill has a parameter to specify a machine to remotely end a process, but I need to start one!
I have tried:
- Map the remote drive to my local PC and then access the files, but of course it will run on my LOCAL PC, not the other PC
- Googling a lot, failing a lot, finding too many 3rd party apps, finding too many C# code snippets
Does anyone know a CLI command that can do this? Just the command or an idea would do, I just need a better starting point.
Some insight would be really appreciated. Thanks
|
|
|
|
|
See_Sharp wrote: Does anyone know a CLI command that can do this? Just the command or an idea would do, I just need a better starting point.
There is no simple CLI 'command' to execute code on remote computers. If it were that simple to execute code on remote machines we would be in big trouble. Mark Russinovich over at Microsoft created a great tool called PsExec [^]which does exactly what your describing. You can even use it in batch files.
It is certainly possible to create a tool which does the same thing. Mark described how psexec is implemented in this WindowsITPro article[^] but unfortunately it requires a subscription to be read. If you look around the net you will find others who have discussed how PsExec works:
PsExec Internals[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you David, I'll definately look into it
I was hoping that something built-in from Windows existed for this, like 'sc', but I guess it can't always be that easy!
|
|
|
|
|
Hi again,
I tried many things now, but nothing worked.
The question isn't really difficult. I have a Status_line label which is
actualised circa 20 times a seconde. In that label is always the actual running
number written. But I do not get rid of that horrible flickering!
I tried already to doublebuffer, but it seems to work only on Graphics.
The writing function has to take the textcolor, backcolor and string as parameter,
so I cannot statically DrawString on the label graphics.
Isn't there a way to prevent that flickering?
Thanks! cherry
|
|
|
|
|
Hi,
1.
AFAIK all Controls can be double-buffered, and that is the best way to improve the situation
2.
some improvement can be achieved by NOT updating the control when all the parameters remain the same,
i.e. compare the current ForeColor, BackColor and Text, with the new ones, and only update when there is a difference.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
No, not all controls can be double buffered. As I tried to enable double buffering on that label,
compiling error C3767 "Candidate Function Not Accessible" appears.
I just can assign doublebuffering to the whole control (it's a control library project), but that has
sadly no effect on the flickering.
I also have tried your second hint, the comparison has also no effect and the fact is, that I have to update,
because in every loop there's number incremented, which I want to display.
So at least the text of the label MUST be changed.
Nevertheless, thank you! Maybe you come up with a further issue..
|
|
|
|
|
cherrymotion wrote: No, not all controls can be double buffered
I haven't encountered a situation yet where I was in need to double-buffer something that did not offer to do so.
cherrymotion wrote: Maybe you come up with a further issue
If the only purpose is to show some progress is (or isn't) being made, I often reverse the initiative: adding a Windows.Forms.Timer that periodically (say every 333msec) checks the situation and reports progress, independent of the work that is going on.
BTW: that timer ticks on the GUI thread, so its handler can update any Control.
PS: for it to work at all, the work itself needs to be handled by another thread (maybe in a BackgroundWorker)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hi,
I started the backgroundworker doing his work, and from the DoWork-Event, I called
timer->start();
but somehow the timer starts never.
In the timer_Tick event I always update my label, I got you right?!
But as I said, the Tick() event is never reached, altough I started the timer.
Do I have to do something else with the backgroundworker? An own thread?
|
|
|
|
|
A Forms.Timer is like a Control, you should only touch it from the main thread, hence outside your worker threads. It needs an Interval value, a Tick handler, and a Start(). It is best to make the timer object a class member of your Form (or other Control).
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hello,
Problem is - User can input any number, program need to take decision based on inputs.
Let suppose input is stored in variable n;
based on value of n some function will be called.
program logic can be -
if(n > 1 && n < 10 )
callfun1();
if(n > 11 && n < 20 )
callfun2();
if(n > 25 && n < 30 )
callfun3();
if(n > 33 && n < 38 )
callfun4();
if(n > 1 && n < 10 )
callfun5();
.
.
.
and so on
if(n > minlimit && n < maxlimit )
callfunX();
Is there any easy way to avoid if else chain to do similar work.
Or is there any way to change the limits in if condition at some central place something using #define.
Please provide your inputs/help to help me finding other ways to optimize programming.
Thank
Vikas
vicky
|
|
|
|
|
Hello.
In .NET you could do something like:
Define an array of minlimits and maxlimits, define a class C to hold your methods, methods that are named in the line of M1, M2 and then use invokemember to call them like this:
For(int i = 0;i<bound;i++)
{
if((minlimits[i]<n)&and(maxlimits[i]>n)
C.GetType().InvokeMember("M"+i.tostring(), .....)
}
In C++ i think you can do this with an array of pointers to functions, but i quit C++ a long time ago and i don't know for sure. Also, the .NET solution is not tested, but looks good:P
modified on Thursday, June 11, 2009 10:10 AM
|
|
|
|
|
vikasvds wrote: Please provide your inputs/help to help me finding other ways to optimize programming.
Software Design Patterns[^]
|
|
|
|
|
Hello!
You could store the intervals in a sorted container together
with the function delegates to call for the specific interval.
You could now use a binary search to find the appropriate
intervals.
However, it gets more difficult when the intervals overlap
and there has to be a certain order. When there are
repeated intervals as above, you could use multicast delegates,
calling callfun1() and callfun5() after each other.
Alex
|
|
|
|
|
Thanks for all of your responses.
I have got the answer.
Thanks
Vikas
vicky
|
|
|
|
|
Please any one know how to run an external application in c++ Windows Forms
|
|
|
|
|
You can use either ShellExecute() or CreateProcess().
Advantage of CreateProcess() function is your program can wait till another application you have launched is not finished/terminated.
Thanks
Vikas
vicky
|
|
|
|
|
Hi,
read up on the Process class. Simple stuff can be handled in a Process.Start() statement; more complexe requirements need details stored in a ProcessStartInfo objects first.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|