|
Does anyone know how to implement the STL sort function or the knows a website that tells you how to implement it.
Thank you,
Juanito
|
|
|
|
|
sort takes two iterates and an instance of the type.
sort(I i1, I i2, T t1)
{
while (i1 != i2)
{
if ( *i1 == t1)
return i1;
++i1;
}
return i1;
}
Actually, the STL code is provided with your compiler, so you can see exactly how they did it, it's in algorithm. I doubt it's much different to the above though.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
sort(I i1, I i2, T t1)
{
while (i1 != i2)
{
if ( *i1 == t1)
return i1;
++i1;
}
return i1;
}
Man, what is that? Seems like a search routine.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Ooops....
I guess I should look more closely....
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Okay. I have determine one major problem, or should I say characteristic of WSASend and/or WSARecv.
For some reason, I cannot call WSASend one after another. For example, let say I call WSASend to send a 4 byte buffer to the client indicating the size of the incoming data. That works find and the client receives the first WSASend package without problems. However, for some reason I cannot call WSASend the second time to send the actual package. The error on the *sending* side is WSAEFAULT:
// WSAEFAULT: "Bad address"
The error on the *receiving* side is WSAEWOULDBLOCK:
// WSAEWOULDBLOCK: "Resource temporarily unavailable"
The bottomline is I cannot send two data buffer consecutively. I am using the WSAAsyncSelect I/O Mode. Is there a specific specification that I missed as far as sending and receiving?
Please message me if you have any ideas.
Thanks,
Kuphryn
|
|
|
|
|
kuphryn wrote:
// WSAEFAULT: "Bad address" More specifically, this means: The lpBuffers, lpNumberOfBytesSent, lpOverlapped, lpCompletionRoutine parameter is not totally contained in a valid part of the user address space. Check the pointers you pass to WSASend.
kuphryn wrote:
// WSAEWOULDBLOCK: "Resource temporarily unavailable"
This simply means that there's no incoming data to be read.
|
|
|
|
|
In asynchronous mode, you shouldn't be continuously calling WSASend or WSARecv , but instead you're supposed to issue only one call to WSASend (WSARecv ) after being notified with FD_WRITE (FD_READ ). Check your documentation for WSAAsyncSelect . Also, you might want to take a look at Warren Young's Winsock Programmer's FAQ.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks.
I am developing the program under WindowsXP and Athlon 750mhz.
I am very, very close to getting everything working as planned. Here is my progress. The program sends data perfectly (I believe). For example:
// Given WSABUF dataHDR, dataMessage
- send header buffer (dataHDR.Buf = data size)
- send data buffer (dataMessage.Buf = message)
// Given WSABUF inHDR, inMessage
- receive header buffer (inHDR = data size)
- use atol() to convert inHDR.Buf into an integer data size
- receive data buffer (inMessage.Buf = message)
Okay. I checked the actual receive size after calling WSARecv for the data buffer. The receive size is accurate, i.e. it received the exact number of byte that was sent. However, I cannot extract all characters from inMessage.Buf.
I use this code to extract the characters from inMessage.Buf
// CString message;
// message += *inMessage.Buf
The problem is the code above only extracts the *first* character in inMessage.Buf. I have considered that maybe only one character or byte is inside of inMessage.Buf; however, according to the check I did above on the actual received size, everything seems accurate.
Am I not converting inMessage.Buf correctly?
Kuphryn
|
|
|
|
|
Can some please tell how I can get a list of the available drives on a system (preferably CD drives). Is there an iteretor that I can using or something like that?
thanks,
Vic
|
|
|
|
|
Use GetLogicalDriveStrings to get a list of the drive letters.
Then use GetDriveType and check the return value for DRIVE_CDROM.
Like it or not, I'm right.
|
|
|
|
|
|
Can some one please tell me a simple method for setting the min values for the resizing of a dialog box (i.e. the box cannot be resized any smaller)
I know there is a way by changing the GetMINMAXValues function, but I somehow wasnt able to implement it.
Thanks, Vic
Vic
|
|
|
|
|
You could handle the WM_SIZE message and change the values if they are too low.
Like it or not, I'm right.
|
|
|
|
|
Use SetWindowPlacement with WPF_SETMINPOSITION.
|
|
|
|
|
ok... in this code... you dont have to worry where everything is being defined or what headers im using,... wheres my functions... this is just the main program... It all works the first time through, then, the cin stops working:
int main()
{
for(;;)//main loop
{
gets(SName);
cin >> SGPA;
person.SetName(SName);
person.SetGPA(SGPA);
cout << person.GetName() << endl << endl; //print name that you just typed.
for(int inc = 0;inc < NN;inc++) //print all names.
{
cout << Names[inc] << "\t" << GPAS[inc] << endl;
}
inc = 0;
}//end main loop.
return 0;
}
in the program is waits for input for the name of sombody... then it goes on to the next thing... which is my cin statment, asking for the float "GPA" of the persons name you put in. after the first time you run through the on going loop... your not able to insert a GPA, rather, for every new name you put in... it applies the original GPA to the names.
Q~How do i reset my cin or get it to work everytime in the loop. set it to null?
Thanks!
~SilverShalkin
i have a fealling that it might not be the cin but i'll see in a bit
|
|
|
|
|
cin.flush() should solve your problems, I reckon.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
CString str = "8000";
doulbe dbl;
dbl = atof( str );
dbl = dbl / 1000;
str.Format( "%d", dbl );
MessageBox( str );
Should that output 8, or is it wrong?
-Raffi
|
|
|
|
|
It is wrong.
When you say %d str.Format expects an integral argument 4 bytes wide. Double is 8 bytes wide so str.Format takes the leading 4 bytes and displays it thinking it to be a valid integer.
|
|
|
|
|
you are correct!
str.Format( "%d", int (dbl) );
is ok!
|
|
|
|
|
Use %f instead of %d
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Raffi wrote:
doulbe dbl;
Am I the only one that noticed 'doulbe' or did everyone just disregard that as an error while typing the post?
|
|
|
|
|
I just regarded it as an error - his compiler would report it, and if he couldn't figure that out, he should probably move to Logo.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Does anyone know how I can open a file with iostreams and get it's size without first writing to it ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Probably seek to the end and get the position. that would be the size.
|
|
|
|
|
After I posted, it occured to me: I'm opening an ofstream because I only want to write, and so I need to write before I have a position, but if I open an fstream, I can probably do a read to get that info without writing anything....
thanks.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|