|
DavidCrow wrote:
Can't you check for duplicates as the items are added?
Thats why I was using the std::set as it only allows unique entries, but it was very slow on the insertions.
Having read the above replies, I may not have a choice on the performance and may have to stick with a set instead of buffering in a vector and then removing dups.
I Dream of Absolute Zero
|
|
|
|
|
That is what set does, except it does it in an efficient way.
|
|
|
|
|
RChin wrote:
On a similar not, I tried using std::set to filter duplicate strings, but I found this to be extremely slow.
You may find that using std::hash_set instead of std::set will be faster for storing strings, provided you have a good hash function.
- Mike
|
|
|
|
|
Thanks for the tip Michael
I Dream of Absolute Zero
|
|
|
|
|
Hi.
Have a simple class for which I want to define a << operator
to put some ints on an ostream. Something like this worked
FINE yesterday, before I just renamed my simple class:
<br />
ostream& operator<<(ostream& os, const TimMinSek& t) {<br />
return os << t.tms[TIM] << ':' << t.tms[MIN] << ':' << t.tms[SEK];<br />
}<br />
The t.tms-stuff are the ints from inside my class obviously.
I did:
<br />
#include <ios><br />
using std::ostream;<br />
in the .h-file for this operator function (and I also include it in its .cpp-file), so I can refer to ostreams just fine. The error I get is:
<br />
no operator "<<" matches these operands<br />
operand types are: std::ostream << const int<br />
return os << t.tms[TIM] << ':' << t.tms[MIN] << ':' << t.tms[SEK];<br />
----------^<br />
but it doesn't matter what else i try to feed the ostream& os,
all I can return seems to be 'os' itself! I can't feed chars
to it either, and definately not my precious ints
Ironically, I more or less copied this function from section
21.2.3 in my edition of Bjarne Stroustrup's 'The C++ language'
and I can't tell the difference between his and mine (and besides
mine worked earlier as I said). Puzzling!
Thanks for any help
regards
/Petter
|
|
|
|
|
Hello Guys,
Can anybody of you can give me some ideas or links or code about how to convert .pdf file into .txt file.
Lot of readymade applications are available on net. I don't interested in all those but I want to make my own application for conversation.
Thanking You
C.R.Naik
|
|
|
|
|
You'll need to use the PDF SDK.
|
|
|
|
|
Friends,
Suppose we pass an object of a certain class as a reference to two other classes. It means that the two classes have a "same" copy of an object. This is a type of "composition"
Now insted of "composition", i want to get the same effect using "inheritance" OR i want my derived classes to inherit from "same" base class. Same base class means that the same base subobject. If one class make any change in the data of its parent, then the change should get reflected in the second class as its parent is same as that of first class.
How is it possible ???
|
|
|
|
|
What do you actually want to do? Are you a student quoting from your exercise or something?
You should rephrase your question so it actually makes sense.
|
|
|
|
|
Consider the following code:
class Parent
{
public:
SetValue(int a)
{
m_value = a;
}
private:
int m_value
};
class Brother:public Parent
{
brother()
{
SetValue(12)
{
};
class Sister:public Parent
{
Sister()
{
SetValue(8)
}
};
As can be seen above, the two classes "Brother" and "Sister" are derived from the same base class "Parent" Both the children classes have their own copy of "Parent". If the class "Brother" makes any change in the data member of "Parent", then the change will not effect the "Parent" of "Sister" as "Sister" has its own "Parent"
What i want is that, both the children classes should share the "same" parent. And if "Brother" changes the data present in its "Parent", then the data of the "Parent" of "Sister" should also gets changed automatically as both "Brother" and "Sister" will have same subobject "Parent".
How can i achieve this goal.
|
|
|
|
|
Jamal Jamshed wrote:
How can i achieve this goal.
static int m_value;
|
|
|
|
|
|
1) Create a base class that all related classes are derived from.
2) Make any member variables that you wish to be common to all derived classes static members.
3) If you are going to destroy (free) any of the members in the destuctor then you need to add a static reference counter member variable that is incremented in the constructor and decremented in the destructor.
class MyClass
{
static int m_nRefCount;
static int m_nMem1;
static whatever* m_pWhatEver;
...................
public:
...................
};
int MyClass::m_nRefCount = 0;
whatever MyClass::m_pWhatEver = NULL;
MyClass::MyClass()
{
++m_nRefCount;
}
MyClass::~MyClass()
{
if( --m_nRefCount < 1 )
{
if( m_pWhatEver is valid )
delete m_pWhatEver;
}
}
:-DHave a wonderful day.
INTP
|
|
|
|
|
hi..
everytime i start my program (and shut it down afterwards) VS reports two memory leaks.
i've tried the _crtBreakAlloc - technique (Q151585) to spot it.. but the problem is, that the allocation might occur, before i have got a chance to type in the number (i use "step into" to step into the code).. because it doesn't break at this numbers, but when i quit the program, the leaks occur.
is there any other possibility to stop at the allocation, which causes the problem ?(the "double click on line thingie" doesn't work too)
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
how can i use m_Combo.SetItemDataPtr for Combo Box to display each entered number in Edit control.??
I have a Edit Control field to enter variable Numbers and a Combo box from 1 to 10, every Index in Combo Box has to have a certain changed Edit Control Number.
Best reguards!
|
|
|
|
|
Hi!
Once I used "SetUnhandledExceptionFilter()" function to set my own exception filter function.Then I could turn to the filter function when the exception occured.But the problem was that I could not get the exception information(EXCEPTION_RECORD).I wanted to use "GetExceptionInformation()" to get it,but the compiler prompted:'_exception_info' : bad context for intrinsic function',I could not understand it,why?
Thanks!
|
|
|
|
|
The function GetExceptionInformation can only be used in the context of an __except block.
An easy way to use structured exceptions is to define an SE handler using the C run-time function _set_se_translator() . The CRT takes care of wiring everything together for you, so you don't have to worry about SetUnhandledExceptionFilter etc. You can even avoid __try/__except blocks by throwing a C++ exception.
Brad
|
|
|
|
|
Brad Sokol:
Your solution is good! Thanks very much!
Now I can do it well.
On the other hand,I have another idea in my exception function,I want to get more information about the locale of exception,such as the information of the stack,like the vc++'s debug tools!
Thanks!
|
|
|
|
|
Getting a stack trace including source file and line number is possible in both debug and release builds. The key is the EXCEPTION_POINTERS parameter. You need to use the symbols engine API which is in the dbghelp.dll library in the Platform SDK to translate the exception pointers into more useful information.
The best reference I've found for this is "Debugging Windows Applications" by John Robbins. He used to write the Bug Slayer column in MSDN magazine. You can find lots of his archived articles over at the href='http://msdn.microsoft.com'>MSDN site.
There is probably lots of useful stuff elswhere on the web but I don't have any links handy. Google for StackWalk or "win32 stack trace" and you'll probably find some useful links.
HTH
Brad
|
|
|
|
|
when i install ms SDK,systen tell me:
—hrror:System platform Windows2000 was detected,so MSI installation was not performed,however a current MSI installation wat not detected.MSI is required for Platform SDK setup?br />
so i can not install it sucessfully.
what aout it ?how to solve it?
thanks in advance!
|
|
|
|
|
Windows Installer Package (.msi) Files
That's all I know.
INTP
|
|
|
|
|
I want to print the content of a CRichEditCtrl. So far no problem for me, I know how to do it.
My problem is that I have to know the size of RTF text on the paper before I start the printing.
So I have to measure the size of the text depending on the resolution of a DC. If I have to print normal ASCII text I use the CDC::DrawText method with the option DT_CALCRECT which gives me the size of the text section for the given DC. Is there a simmilar method for RTF text?
As a workaround I think of using the CRichEditCtrl::FormatRange method and calculate the size iterative by giving a guessed value for the text rectangle to FormatRange and see, if all charcters fit into the rectangle. Now I size the rectangle until all characters fit into the rectangle.
Has anyone an idea how to solve the problem or is this the only solution?
Thanks in advance.
|
|
|
|
|
There is another solution: using windowless richedit
but you'll need to know COM
1. loadlibrary richedit.dll
2. obtain the CreateTextServices proc : GetProcAddress( hRichDll, "CreateTextServices" )
2. obtain the IID_ITextService : (GUID*)(GetProcAddress( hRichDll, "IID_ITextHost" ))
3. create an instance of ITextHost (a dummy one) .. read the doc
3. call query interfce for the ITextService
IUnknown* unk = NULL;<br />
(*fnCreateServices)( NULL, &m_TextHost, &unk );<br />
unk->QueryInterface( g_RichService, (void**)&m_Service );<br />
unk->Release( ); 4. send the rtf to the service
m_Service->TxSendMessage( EM_STREAMIN, SF_RTF, ... (doc)... )
5. ask the natural size
long forHeight = 1;<br />
SIZEL sze;<br />
sze.cx = forWidth;<br />
sze.cy = forHeight;<br />
<br />
m_Service->TxGetNaturalSize( DVASPECT_DOCPRINT, m_hDC, 0, NULL, TXTNS_FITTOCONTENT, (SIZEL*)<br />
&sze, &forWidth, &forHeight );
i cannot give you the whole source of the implementation of ITextHost because it should be too long, but read the ITextHost doc and implement the strict minimum.
i use that way to create dynamic rtf, calculate rtf display size, print rtf ...
notice that under XP, you should use 'msftedit.dll' instead of 'richedit.dll'
msftedit is really really faster.
good luke
|
|
|
|
|
arg mistake, read that
2. obtain the IID_ITextServices : (GUID*)(GetProcAddress( hRichDll, "IID_ITextServices" ))
|
|
|
|
|
Thank you for your detailed answer!
I hoped I could work with RTF without using COM, but I think I can not escape the Microsoft doctrine.
|
|
|
|