|
Thank you.
This makes the lstrcpy better than _tcscpy... to write better programs!
Thank you once again.
- NS -
|
|
|
|
|
NS17 wrote: _tcscpy or lstrcpy
offcourse lstrcpy is better as it reduce the dependency of runtime c library.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
|
lstrcpy is a function of Windows API and _tcscpy is from C Runtime Library. This is the basic difference. Otherwise, both resolve to same things.
lstrcpyA does the same job as strcpy. lstrcpyW does the same job as wcscpy. (So lstrcpy does the same job as _tcscpy.) It's useful to use lstrXXX if you feel the need to eliminate the C library entirely.
Ahh... I didnt see Alok's reply. He had already said this.
-- modified at 0:59 Friday 23rd December, 2005
|
|
|
|
|
Thank you.
Please see the post of Blake Miller, which is also very significant.
- NS -
|
|
|
|
|
HI
I have written some class for learning and understanding ... but i got lost
At the beginning i learned "templates" the use of Iterators
Now i like to combine these Methodes
<br />
#if !defined(_TQUEUE_H_)<br />
#define _TQUEUE_H_<br />
<br />
<br />
typedef struct CPointPlus<br />
{<br />
CPoint m_punkt;<br />
int m_attribut;<br />
float m_freq;<br />
}CPointPlus;<br />
<br />
template <typename T><br />
class TQueue <br />
{<br />
public:<br />
typedef struct tqueue<br />
{<br />
struct tqueue *next;<br />
T entry;<br />
struct tqueue *prev;<br />
}tqueue;<br />
<br />
TQueue();<br />
virtual ~TQueue();<br />
<br />
void gethead();<br />
void gettail();<br />
void push(T*);<br />
T* getnext();<br />
T* get();<br />
void destroy();<br />
<br />
class Iterator;<br />
friend class Iterator;<br />
<br />
long counter(){return m_count;}<br />
private:<br />
long m_count;<br />
tqueue *first;<br />
tqueue *last;<br />
};<br />
<br />
template <typename T><br />
class TQueue<T>::Iterator<br />
{<br />
public:<br />
Iterator(TQueue &tq):g(tq)<br />
{}<br />
~Iterator()<br />
{}<br />
void reset()<br />
{<br />
aktuell = first;<br />
}<br />
void next()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->next;<br />
}<br />
}<br />
void prev()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->prev;<br />
}<br />
}<br />
T* get()<br />
{<br />
if(aktuell)<br />
return aktuell->eintrag;<br />
return NULL;<br />
}<br />
private:<br />
TQueue &q;<br />
tqueue* aktuell;<br />
};<br />
<br />
The cpp for TQueue is working fine ...
Now how to change the cpp part of Iterator to write this into TQueue.cpp??
And how to call the Iterator ??
<br />
TQueue<CPointPlus>::Iterator it(queue);<br />
is not working...
THX
LOL
T
-- modified at 6:15 Thursday 22nd December, 2005
|
|
|
|
|
Moin,
if you want to rewrite the STL's queue, the iterator should be used as follows:
TQueue<CPointPlus>::Iterator PointIter;
And then you could use it in a for-loop as follows:
for(PointIter = queue.begin(); PointIter != queue.end(); PointIter++)
{
}
I hope that gets you back on track. And if you have worked with the STL before, have a look at my problem and give me some hints
Der Weg ist das Ziel
For everyone not speaking German (in order to better understand tbrakes code):
Aktuell = current, actual
Alt = old
Punkt = point
The german comment says: overwrite at current pointer and move to next.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
-- modified at 7:41 Thursday 22nd December, 2005
|
|
|
|
|
HI
THX but using
<br />
TQueue::Iterator PointIter;<br />
Tells me template argumentlist missing
and
<br />
TQueue<CPointPlus>>::Iterator PointIter;<br />
tells me undefiened class Iterator
And now ??
THX T
|
|
|
|
|
I took it that you were trying - for training - to rewrite a simple "STL-like" queue and wanted to provide an "STL-like" Iterator for it.
If I had a STL vector like
std::vector<int> myIntVector;
then I would declare my iterator as follows:
std::vector<int>::iterator myIntIterator;
and use it in a for-loop in this manner:
for(myIntIterator = myIntVector.begin(); myIntIterator != myIntVector.end(); myIntIterator++)
{
std::cout << *myIntIterator << std::endl;
}
Ich denke einfach, du hast mehr davon, wenn du selbst drauf kommst.
Edit: Sorry, I didnt notice the board dropping the <tags>.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
-- modified at 7:40 Thursday 22nd December, 2005
|
|
|
|
|
Hi
Fine... Iterators themself are not hte problem and using stl is not the problem too.
But I like to know to manage my special QUEUE double linked template class with my own special ITERATOR for dynamic queues holding about 3.000.000 entries (each QUEUE) no arrays used!!!
Please tell my how to manage.
Ein Synonym für "kann ich nicht" lautet "trivial" oder "das bleibt dem Leser überlassen" ...
CU T
|
|
|
|
|
Sry, this has to be written in German. There was an musunderstanding.
Hallo tbrake,
Das ist auf keinen Fall trivial. Aber das wollte ich auch nicht ausdrücken. Was ich dir mitteilen wollte war: warum schaust du dir die STL nicht an? Es gibt genug C++ Standard Libraries, die im Quelltext verfügbar sind.
Ich wollte auf keinen Fall den Eindruck vermitteln, ich hielte mich für etwas Besseres. Ich hatte einfach unglaublich gute Laune (und dachte, das käme so rüber, sorry) und wollte dir vermitteln, dass du genug Quellen hast, um dein Problem zu lösen. Deswegen kam die Abkürzung STL auch so häufig in meinen Posts vor.
Das war nicht böse gemeint, und es tut mir leid, das du es so verstanden hast.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hi
1.
my Solution for Iterator...
<br />
template <class T><br />
class TQueue <br />
{<br />
public:<br />
<br />
typedef struct tqueue<br />
{<br />
struct tqueue *next;<br />
T eintrag;<br />
struct tqueue *prev;<br />
}tqueue;<br />
<br />
<br />
<br />
class Iterator<br />
{<br />
public:<br />
Iterator(TQueue<T> &tq):q(tq) {}<br />
~Iterator() {}<br />
void reset() {aktuell = q.getfirst();}<br />
void next()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->next;<br />
}<br />
}<br />
void prev()<br />
{<br />
if(aktuell)<br />
{<br />
tqueue *alt=aktuell;<br />
aktuell = alt->prev;<br />
}<br />
}<br />
T* get()<br />
{<br />
if(aktuell)<br />
return &(aktuell->eintrag);<br />
return NULL;<br />
}<br />
private:<br />
TQueue<T> &q;<br />
tqueue* aktuell;<br />
};<br />
<br />
<br />
<br />
TQueue();<br />
virtual ~TQueue();<br />
<br />
void gethead();<br />
void gettail();<br />
void push(T*);<br />
T* getnext();<br />
T* getprev();<br />
T* prev();<br />
T* get();<br />
void destroy();<br />
<br />
<br />
tqueue *getfirst(){return first;}<br />
<br />
long counter(){return m_count;}<br />
public:<br />
long m_count;<br />
tqueue *curr;<br />
tqueue *last;<br />
protected:<br />
tqueue *first;<br />
};<br />
This is working :->
Not written the way i like to have it .. but working (so far)
2.
MeTo in orefull german
Wollte Dir auch nicht Deine Laune miesmachen ... sitze jetzt aber schon ein paar Stunden an diesem Problem ... Leider kann ich auch nicht so einfach auf stl umsteigen ... Habe hier ca 300 Klassen mit je 1000 Zeilen Code ... und dann ist es am einfachsten wenn Du es einfach nur erweiterst ...
Schwamm darüber ... es funst !!!
THX
CU
Timen
|
|
|
|
|
Yeah, sponge over...
I am closing on the solution to my problem, too.
The funny thing is: If I remove everything else from the sourcefile in question and just leave the structs and the predicate in place, all works well. There HAS to be some freak-up in the sourcefile. Maybe I forgot to remove one of my predecessors jumps - or I made a mistake when I refactored the output to print to a file instead of the screen (which, when printing 400000 lines, DOES make a difference.
Anyway, I am glad you were able to solve your problem.
:-DJust dont break it again, I might not always be here to help you... SCNR, just kidding, I hope its obvious this time
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hi everybody.
It seems that I am unable to solve a problem I recently encountered while trying to use STLs generic "sort(RanIt First, RanIt Last, Pr Pred)". I have a class which evaluates a range of datasets coming from a lower level of one of our plants (I am doing a performance evaluation).
The product-data is stored in a binary file, which is read and fed to my application by a legacy-tool on which I have no modification privileges. Since that tool works well and is blazingly fast (inflating, reading and forwarding up to 10000 datasets per second, each sized around 100 KB) I am OK with that. There is one catch, though: The data has to be written after the final production step of each product is finished. Products no not necessarily take the same path, so they are stored "unsorted". And try to find a single entry in an ascii-log which holds 10000 products, with IDs being 16 digits, where the first 10 digits refers to a certain product attribute and the last 6 digits are auto-incremented.
Basically, I do the evaluation on a "per product" basis and then store the results (just a couple of integer values) in a struct (which contains 2 vectors). I then push that struct into another vector, e.g.:
<br />
typedef struct example<br />
{<br />
int test1;<br />
int test2;<br />
vector<int> Data;<br />
}Example;<br />
and a class ExClass containing a vector<Example> m_Products;
Hell, I figured, I successfully used sort before, so why not use it this time. I #included <algorithm> and wrote a binary predicate:
<br />
bool ExClass::lessProduct(Example &e1, Example &e2)<br />
{<br />
return ( e1.test2 < e2.test2 )<br />
} <br /> (
with the appropiate prototype in the header. Originally, this even was inlined for speed, but I got the same error.)
And I get C2064 claiming: "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1863): error C2064: term does not evaluate to a function taking 2 arguments."
I need help here.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
looking at the error message, i would tend to say that the prototype of the comparator should be better bool ExClass::lessProduct(Example& e);
because the other parameter is this
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
toxcct: Sorry, I believe you misunderstood my example. My mistake.
The Class I am referring to contains both the struct (protected) and the vector_of_struct (private).
STL's sort template offers two prototypes, one takes the start and end iterator, the other one additionally takes a binary predicate.
In that predicate (which also is a member of my class) this would refer to the class, not a second structure.
As I mentioned before, I did exactly the same in another class (and it worked). That's why I am so confused.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
-- modified at 6:51 Thursday 22nd December, 2005
|
|
|
|
|
|
Thanks it worked and gave me an idea:
I removed everything else from the header and just left the structs and predicate in place. It compiled and worked correctly. If I add the remaining header, the compile fails again.
Now I just need to find out why.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hi All,
i am intending to save double array values to blob fiels in MySql database. So i need to convert double value in to BYTE array.
Can anyone help me to convert a double value (8byte) to BYTE array and vice versa.
Thanks in advance
Basheer
|
|
|
|
|
double d = ;
char tab[8];
tab[0] = ((d >> 0) & 0xFF);
tab[1] = ((d >> 8) & 0xFF);
tab[2] = ((d >> 16) & 0xFF);
tab[3] = ((d >> 24) & 0xFF);
tab[4] = ((d >> 32) & 0xFF);
tab[5] = ((d >> 40) & 0xFF);
tab[6] = ((d >> 48) & 0xFF);
tab[7] = ((d >> 56) & 0xFF);
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
unsigned char bArray[sizeof(double)];
double d;
memcpy(bArray,&d, sizeof(double));
reverse:
memcpy(&d, bArray, sizeof(double));
|
|
|
|
|
kakan wrote: unsigned char bArray[sizeof(double)];
won't compile. you have to do it this way :
unsigned char* bArray = new unsigned char[sizeof(double)];
which is why i directly put [8] to ease the code (standard C++ tell that the size of a double is fixed to 8 bytes, so doesn't vary).
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
Hello.
You are right (of course).
But the memcpy is neat, isn't it?
|
|
|
|
|
|
Thanks.
|
|
|
|