|
You're using a function with a hardcoded divisor in it, so the problem is how to get a second parameter into it.
If you want to keep using a function then you can expand your function to take a second parameter:
long double op_divide( long double numerator, long double denominator ) { return numerator/denominator; }
and use std::bind2nd to create a function object to pass to transform:
transform( vec.begin(), vec1.end(), vec2.begin(), std::bind2nd( op_divide, 5.0 ) );
[That's unchecked BTW, I'm not on a computer with a compiler on to check it - I'm pretty sure it will though.]
If you're doing that you could try using std::divides which does the same thing and saves writing the function.
Cheers,
Ash
|
|
|
|
|
Thanks Ash. I implemented the code, but it is giving many errors, the first being:
error C2825: '_Fn2': must be a class or namespace when followed by '::'
and the 2nd:
error C2039: 'first_argument_type' : is not a member of '`global namespace''
|
|
|
|
|
Ooops, forgot to add in the bit of special sauce to convert the binary function pointer to a function object:
std::transform( input.begin(), input.end(), output.begin(), std::bind2nd( std::ptr_fun( op_divide ), 5 ) ) );
What you've got is a function that takes two arguments. The std::ptr_fun function returns a function object, the function call operator of which passes the arguments to the contained function. The std::bind2nd returns another function object:
- the function call operator takes 1 parameter
- the constructor of the object stores another parameter
- the function call operator passes the 1 parameter and the stored parameter through to the contained binary function object which passes them through to the contained function pointer.
Arrrgggghhhhh... I want me Lambda's back!
Cheers,
Ash
PS: That's as clear as mud, I'll try and clean it up later
|
|
|
|
|
worked great, thanks Ash!
|
|
|
|
|
Here's one way:
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <functional>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
vector<double> nums;
for (int i=1; i<=10; ++i)
nums.push_back(i);
cout << "Before: ";
copy(nums.begin(), nums.end(), ostream_iterator<double>(cout, " "));
cout << endl << endl;
transform(
nums.begin(), nums.end(),
nums.begin(),
bind2nd(divides<double>(), 2.0)
);
cout << "After: ";
copy(nums.begin(), nums.end(), ostream_iterator<double>(cout, " "));
cout << endl << endl;
return 0;
}
Steve
|
|
|
|
|
|
Hi guys how can i accomplish this i need to show a do you want to update message every time the app is started the first time windows has rebooted.
Thanks!!
|
|
|
|
|
You could check for a 'flag' in some configuration file or the registry. After your app runs, set the flag to some other value (or remove it).
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
ok, but how do you detect that windows has reboot??, i mean i put a registry key called "doUpdate" value=false then i start my app i change that registry to true, so the next i launch my app it will not show the message that is ok, but how to reset that value when windows is restarted?
|
|
|
|
|
You might could take advantage of the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run key by putting a small app there that runs the next time Windows is started.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
ok i did that but every time windows starts up i shows the black window and then closes is kind of anoying is there a parameter to put there so it runs silently?
|
|
|
|
|
It shows a black window because you made a console application.
Make a normal win32 one, just don't create any windows.
Have it set a registry value
(eg) HKCU\Software\ManchukuoSoft\MyAmazingApp\Rebooted = 1
Then, when your real MyAmazingApp is run, check the value, and maybe show a message. Then clear that value.
Job done!
Iain.
I have now moved to Sweden for love (awwww).
|
|
|
|
|
Thanks guys that did the work!!! . This is Fixed
|
|
|
|
|
Perhaps you could create a registry key using RegCreateKeyEx[^] and use REG_OPTION_VOLATILE as the option.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
you will need 2 programs for this. One will run as autorun (startup) and set a value in registry (say reboot = true). Another program whent started by user, will check this value in registry and if it is true then display your messagebox and set the value to false.
|
|
|
|
|
Has anyone tried implementing HTTPS protocol in a C++ application.
I started reading the RFC2818, but I'm confused over implementation.
|
|
|
|
|
I would recommend RFC2616[^] as a starting point and than blend it with a SSL/TLS library instead of using TCP. The library should take care of most encryption/certificates handling (e.g. have a look at OpenSSL, GnuTLS, Microsoft's CryptoAPI). Alternatively use a library from the shelf that offer HTTPS (e.g. libcurl, WinInet, QHttp).
You need to decide if you want to implement everything yourself or take an existing C++ library. First will teach you a lot about networking protocols, later gives you the result right away. Hope this helps!
/M
|
|
|
|
|
Moak wrote: First will teach you a lot about networking protocols, later gives you the result right away.
Nice reply in general. I'd change the bit I quoted to read as follows:
The first will teach you a lot about networking protocols and convince you to go with the second.
Steve
|
|
|
|
|
Hi i have an MFc application which is compiled in Visual studio 6 .
I have created a dll that is compiled in VS2005.
It works fine on development machine giving me all desired results.
But after deploying the exe and dll on Other machine which is meant to be for testing purpose. I copied all the dependent dll in the same folder is required for dll that is compiled on VS2005.
But the dll is failed to load using loadlibrary.
To solve this issue i created a setup of MSM of Visual studio Merge module and installed on the Testing machine. I was expecting that this will atleast solve my prioblem but it also failed to load dll.
Any one has suggestion that how this can be achieved?
|
|
|
|
|
try Depends[^] to see if there are any missing DLLs.
|
|
|
|
|
PrafullaShirke27 wrote: But the dll is failed to load using loadlibrary.
Did you call GetLastError() to find out why?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Thanks guys for response.
I tried depends and added the necessary dll for that and GetLastError too.
And according to that The operation was successful.
|
|
|
|
|
Hi all,
I want to make a picture control in which i can display various types of images like bmp, png, ico and i want at runtime if i select a path than that images should display according to path.
But my problem is i don't want to use gdiplus lib in my code....
Can i do this work without using gdiplus if yes than how so
Thanks in advance
|
|
|
|
|
The CxImage[^] library would do the trick for you.
|
|
|
|
|
there are dozens of graphics libraries out there.
|
|
|
|