|
ok, thanks for your reply. First this not a homework, this is an idea that came to my mind and tried to implement it yet I failed ...
what I understood from your solution is that it will work with just two inputs, but I want to work with various number of inputs as I stated before ...
I was thinkin of making the size of the string constant and then generate strings using the input characters to generate the strings under one constraint, the size of the string should be less than or equal to the number of input elements ... I`ll try to implement it using you sample solution ...
Hope my question is more clear now ...
|
|
|
|
|
The first thing to recognise is that when you're generating your strings you're just counting. Represent a by 0 and b by 1 and your example is:
00
01
10
11
And if you had three letter, a, m, z you could represent them by the digits 0, 1 and 2:
000
001
002
010
011
012
020
021
022
100
101
102
110
111
112
120
121
122
200
201
202
210
211
212
220
221
222
You're counting in base 2 in the a,b case, base 3 in the a,m,z case.
So you're going to get a number of solutions equal to the number of letters raised to the power of the number of letters - this gets big real quick. 4 letters has 256 combo, 5 letters has 3125 and so on.
For a brute force approach "all" you've got to do is:
- generate and the integers in the range ]0, n raised to the power of n]
- convert each number into a string of digits in base n
- convert each string of digits into a string of characters
This is one use of std::generate_n and two uses of std::transform.
With a bit more care you can collapse all three into call of std::generate_n with a bit of class building. I've wittered on enough for now - if you'd like more information just shout.
Cheers,
Ash
|
|
|
|
|
In VS 2008 it complained about the need of the newest windows SDK.
I've installed VS 2010 which is shipped with v7.0 but Intel Compiler still complains.
Is there newer than VS 2010 SDK available?
Чесноков
|
|
|
|
|
Hi,
I a bit confused to use OLE service for Crichedit
I use the SetOleCallBack to set the pointer ???
If yes
then What is GetIRichEditOle all about
thankx
|
|
|
|
|
Hi all,
1) Can we use free() function to free the memory allocated by "new" operator.
2) Can we "delete" operator to delete the memory allocared by malloc() function.
Thanks in advance
sAI
|
|
|
|
|
new and delete can be overloaded, so generally speaking, you can't do that.
|
|
|
|
|
You shouldn't. It may or may not work, depending on the implementation.
Steve
|
|
|
|
|
The short answer to both these questions is: No, never, ever, ever, ever mix calls to new/delete and malloc/free.
The long answer is that, unlike malloc and free, new and delete don't allocate and release memory, they create and destroy objects. If you try and free an object created by new the destructor for the object won't be called, if you malloc a block of memory the constructor for whatever type you assign the pointer to won't be called.
Cheers,
Ash
PS: In case I haven't said it strongly enough, don't do it. Really. Future generations of maintenance programmers will curse your name if you try it.
|
|
|
|
|
These methods are to be used in pairs and you should not mix them.
If you allocate memory with malloc then you need to free it with free . The same goes for new and delete .
C Memory Functions
malloc : Allocates an uninitialized block of memory, given the number of bytes.
calloc : Allocates a zero initialized block of memory, given the number of elements and the size of the element.
free : Deletes the memory allocated by malloc or calloc .
C++Memory Operators
new : Is an operator that allocates storage for one or more elements (objects) and then calls the constructor of each element to initialize it.
delete : Is an operator that calls the destructor for each of the stored elements and then frees the associated storage.
As you can see from the above, new is not equivalent to malloc and delete is not equivalent to free . They are not enterchangable and should not be mixed. When writing C++ code you should use new and delete , unless you have a very good reason not to.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
If you try to write a code, using this option it will compile but at run time the
1) Combination of malloc and delete get crashed
2) If you allocated memory for object using new and try free for deallocating memory there will be memory leakage problem because destructor never call by free
|
|
|
|
|
Combining malloc and delete might not cause a crash - with a couple of the compilers I use I'm pretty sure I can write code that allocates memory with malloc and deletes an object where that block was allocated without a crash. I shouldn't though as it requires a lot of knowledge of how the compiler's runtime works and is about as portable as a suitcase of bricks.
Likewise if I call free on an object I created with new I might not get a memory leak. Yes, the destructor won't be run but the destructor isn't the thing that releases the primary memory of an object.
Ash
|
|
|
|
|
Hello
sry for may bad english im a Austrian
Ok now my question
I have a litle Prog witch opens a txt file from my local hdd, now i want to open a txt file from my web serv and put it out on te consol.
But how can i open the file ?
it doesn't work
ptr = fopen("\\http://king.ath.cx//server.txt" ,"r+");
if(ptr == NULL) {
printf("\nfopen error\n");
getchar();
Lg
Alex
|
|
|
|
|
You must first copy the file onto your local disk, either through your browser or via FTP.
It's time for a new signature.
|
|
|
|
|
I can say one of old style of coding (not a .net style, I'm saying) with WinInet.
The primary usage is thus;
<pre>
HINTERNET hInet = InternetOpen("MyLocalAgent", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
HINTERNET hFile = InternetOpenUrl(hInet, "http://king.ath.cx/server.txt", NULL, 0, 0);
BYTE buffer[BUFSIZE];
DWORD dwRead;
while (InternetReadFile(hFile, buffer, BUFSIZE, &dwRead)) {
if (0 == dwRead) break;
fwrite(buffer, 1, dwRead, stdout);
}
InternetCloseHandle(hFile);
InternetCloseHandle(hInet);
</pre>
|
|
|
|
|
You could either open it using a UNC path, or try using URLDownloadToFile() .
"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
|
|
|
|
|
but URLDownloadToFile() cannot down the LAN's web server ,like this : http://192.168.1.200/myfree.txt
|
|
|
|
|
You could use CInternetSession , CSdioFile , CHttpFile and CInternetFile MFC classes to read data from remote file based on HTTP and FTP protocols.
Life is a stage and we are all actors!
|
|
|
|
|
But how can I do it could you help me
|
|
|
|
|
You may start your research from here.
Life is a stage and we are all actors!
|
|
|
|
|
I am creating an activex control using directshow in vc++ mfc.
when I realese the interface IGraphBuilder then application is crashed in windows vista but in windows xp it works fine.
why it is happened .
|
|
|
|
|
> why it is happened .
Os is very different. It is just a reason.
Generally, many program which can run on xp will not be able to run on vista because of incompatibility between xp and vista.
The most incompatibility of os is around security.
Check the API's document you used, and you might find some clue of them; incompatibilities.
|
|
|
|
|
My excel file cell value is changing but I am not getting the change event . value is updating with some other software . is there is any setting in excel file
Trioum
|
|
|
|
|
You must watch every time its file changing if you want know.
I don't know the general watching process for the reason.
So, you can write some code which reads the file and sense difference of it by yourself.
|
|
|
|
|
Hi all,
What I am trying to do is transfer a screenshot over a socket. I can get the screenshot into a Bitmap type, and I can even save it as a JPEG file by getting the CLSID of the encoder. However, I want to do this without an intermediatary file - that is, I want to be able to turn the Bitmap into a JPEG binary array and send it directly over the socket. I'm currently stumped at the turning the Bitmap image into a binary JPEG part - any suggestions would be nice. Or, if there is an easier way to do this that I'm missing, please assist. Been googling for a while now to no avail.
Thanks
|
|
|
|
|
Okay, I've made a little progress:
Gdiplus::Bitmap bitmap(membit, NULL);
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
IStream* tmpbuf = NULL;
CreateStreamOnHGlobal(NULL, true, &tmpbuf);
bitmap.Save(tmpbuf, &clsid);
tmpbuf->Release();
How do I change the IStream* into a byte* (and how do I determine the size beforehand)?
|
|
|
|