|
Just as a reference for the comments below, from the Microsoft Documentation:
template <
class Key,
class Type,
class Traits = less<Key>,
class Allocator=allocator<pair <const Key, Type> >
>
MatthewP wrote:
how the predicate 'op' differs in each map example below
The comparison of keys defaults to using std::less<Key>, which relies upon a less than operator being available. In examples 1) and 3) a custom comparison functor needs to be supplied. In 2) the default is used.
MatthewP wrote:
why op needs to be a class or struct with the predicate specified in an overloaded () operator
It doesn't. All it needs to do is provide function call notation, it could be a function, but is generally implemented as a class or struct.
MatthewP wrote:
why when I use #2 or #3 I loose the ability to change an element using map[key] (such as ++map[key])
From the Microsoft Documentation:
Type& operator[](
const Key& _Key
);
You can, you just need to make sure that the types of the template paramters match the types of the comparison functor.
MatthewP wrote:
if it is possible to order the elements based on the elements(elem) themselves
If this is a problem perhaps a map isn't the appropriate data structure. Sometimes sorted or associative vectors (or even sets) may give better performance or model the problem domain more closely.
Look at the common operations (in performance critical code) that you'll be using the container for, and select the container based upon those operation. Are inserts, removes or updates the most frequent operations? Most operations are cited in big oh notation, and are easy to get.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Can someone please explain 1) how the predicate 'op' differs in each map example below, 2)why op needs to be a class or struct with the predicate specified in an overloaded () operator , 3) why when I use #2 or #3 I loose the ability to change an element using map[key] (such as ++map[key]), and 4) if it is possible to order the elements based on the elements(elem) themselves (i.e. not the key). Thanks!
1) map<key, elem, op> m;
2) map<key, elem> m(op);
3) map<key, elem, op1> m(op2);
Matthew
|
|
|
|
|
This definition of map should provide most of the information you need: STL map[^]
|
|
|
|
|
I is have application for personal assistance, and is use some date and time functions. I am using C++ in the .NET. When is compiled on XP computer, is not runs correct on 2000. When is compiled on 2000, then is runs rightly on both XP and 2000.
Does anyone knowing of compatabile problems with XP/2000? Maybe problem with .NET?
Thanksing...
|
|
|
|
|
what excactly does not work correctly?
Don't try it, just do it!
|
|
|
|
|
Not surely what is wrong since can not debug because only when running the XP version on 2000 is not working. When I compiles on 2000 is working fine.
In the start of program I get the today date to start, and the informations on my screen is wrong. But then later in program when I get today date it is right, and so is the informations.
Also, the spin control sometimes jumps 2 instead of 1 when compiled on XP. When is compiling on 2000 then only jumps by 1.
Thanksing...
|
|
|
|
|
Are there any choices how to create an ActiveX in VS? I see there is a possibility to create an ActiveX-project but I like the dialog drag-and-drop style when creating my MFC-apps. May I create an ActiveX “drag and drop” project in either VS 6.0 or VS .NET?
Any suggestions on ActiveX-articles would please me very much.
...and justice for all
APe
|
|
|
|
|
I have a GPS program serially reading incoming data. A sample of my code is below.
// get speed
Code = mgcGetData(GPRMC_SPEED,(LPSTR)DataBuffer);
if(Code<0) ShowMGC32Error(Code);
if(Code>0) printf("%5s ", DataBuffer);
I have the program printing a few of these data buffers to the screen. I was wondering how to store this data file readout into a actual variable so i can do some calculations
i cant just do variable=databuffer;
???
|
|
|
|
|
TCHAR szData[16];
wsprintf(szData,_T("%5s"),DataBuffer);
or use sprintf,(CRT Library)
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|
i get these errors
C:\Program Files\Microsoft Visual Studio\VC98\MGC4C\apps\gprmc.c(125) : warning C4013: '_T' undefined; assuming extern returning int
C:\Program Files\Microsoft Visual Studio\VC98\MGC4C\apps\gprmc.c(125) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
C:\Program Files\Microsoft Visual Studio\VC98\MGC4C\apps\gprmc.c(125) : warning C4024: 'wsprintfA' : different types for formal and actual parameter 2
|
|
|
|
|
include tchar.h in stdafx.h
or
remove _T() mark
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|
I assume you want to convert a string of some form into a number of some form. So look at 'atoi' as a first pass, then 'strtoul' and it's relatives, possibly 'scanf'.
Paul
|
|
|
|
|
I am trying to write an App that receives Data from the Serial Port, but I am having trouble finding out what type that data is and where it can be stored when it comes through the serial port
Whether it be a character string or otherwise.
I need to know because I want to Manipulate that string when it comes through
Anyone know?
|
|
|
|
|
Hi,
Serial device uses byte streaming in order to send and receive data. Therefore, you can use char array to store your data.
Regards,
Ahmet Orkun GEDiK
System & Software Support Specialist (SAP R/3)
ASTRON
|
|
|
|
|
Thank you for the quick response Ahmet.
To clarify, When you say Byte, What is considered a Byte?
Is '7' a byte or is '7F' a byte?
thank you and believe me, I need as much clarification as possible.
|
|
|
|
|
I mean, 'A' is 0x65.
Your welcome.
Ahmet Orkun GEDiK
System & Software Support Specialist (SAP R/3)
ASTRON
|
|
|
|
|
Serial ports have variable numbers of data bits per character. This goes back to Baudot coding for Telex transmissions sometime in pre-history which I think was only 5 bits per char. ASCII would be 7 bits. Most serial ports (and all those on a PC) will do 8 bit characters.
Each character (of however many bits) received from a serial port will end up as a 'char' in your data buffer. This character is just a bit pattern, a number, whether it is interpreted as 'A' or not is down to the coding you've chosen. So 0x65 is alway 0x65 but not necessarily 'A'.
If you could enlarge on what you want to do, how you want to do it, and where you are now, then I/we could be specifically helpful.
Paul
|
|
|
|
|
Paul, I would be more then happy to further engage you on what I am doing in Private, but I do not feel real comfortable talking about it in public.
|
|
|
|
|
Hi guys,
I am wondering what are the benefits to include
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
optional macro.
I can see it's automatically genrated in my stdafx.h header file. But if I do not have it removed, I will get conversion error from wchar_t to CString in my program. If I want allow this specific conversion, how do I explicitly define it?
Thanks
|
|
|
|
|
Hi, I am creating an FTP client in C++ using MFC. I just started the project, so I have a few questions:
1) Should I be using a dialog mfc app for this because I want it to be similar to WS_FTP.
2) What type of dialog control would I use for showing the contents of the user's local working directory and the remote working directory...A list control?
3) Now, what is the easiest way to show the contents of the working directory. Is there a function I can use?
I appreciate all comments and suggestions. Thanks!
|
|
|
|
|
1) Yes. (SDI CFormView might be a choice as well, but that depends on how complex you want things)
2) Yep, that is a reasonable choice.
3) When it comes to this question, I'm not too sure.
Happy Programming and God Bless!
WWW::CodeProject::BNEACETP
|
|
|
|
|
CWnd::DlgDirList() will populate a list box with the names of files in a directory. But if you want a more professional look, use PJN's CTreeFileCtrl[^] to display files and folders.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
i want to allow a user to enter a website address (eg. www.microsoft.com) into a text box
and i can then resolve this address to its IP address.
i am sure there is a function for this,
but i cannot find it
thanks
|
|
|
|
|
Hi,
You can use "accept(hSocket,(struct sockaddr*)&stcSockaddrCln,&iSocketSize)" in order to accept incoming request. If you want to resolve dns to ip number, you may use "inet_ntoa(stcSockaddrCln.sin_addr)".
I hope it's good enough for you.
Regards,
Orkun Gedik
Ahmet Orkun GEDiK
System & Software Support Specialist (SAP R/3)
ASTRON
|
|
|
|
|
This function is the one you r looking for---->
gethostbyname
The Windows Sockets gethostbyname function retrieves host information corresponding to a host name from a host database.
struct hostent FAR *gethostbyname(
const char FAR *name
);
Parameters
name
[out] Pointer to the null-terminated name of the host to resolve.
Return Values
If no error occurs, gethostbyname returns a pointer to the HOSTENT structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.
Error code Meaning
WSANOTINITIALISED A successful WSAStartup call must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAHOST_NOT_FOUND Authoritative answer host not found.
WSATRY_AGAIN Nonauthoritative host not found, or server failure.
WSANO_RECOVERY A nonrecoverable error occurred.
WSANO_DATA Valid name, no data record of requested type.
WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEFAULT The name parameter is not a valid part of the user address space.
WSAEINTR A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall.
Remarks
The gethostbyname function returns a pointer to a HOSTENT structure—a structure allocated by Windows Sockets. The HOSTENT structure contains the results of a successful search for the host specified in the name parameter.
The application must never attempt to modify this structure or to free any of its components. Furthermore, only one copy of this structure is allocated per thread, so the application should copy any information it needs before issuing any other Windows Sockets function calls.
The gethostbyname function cannot resolve IP address strings passed to it. Such a request is treated exactly as if an unknown host name were passed. Use inet_addr to convert an IP address string the string to an actual IP address, then use another function, gethostbyaddr, to obtain the contents of the HOSTENT structure.
The gethostbyname function resolves the string returned by a successful call to gethostname.
Requirements
Version: Requires Windows Sockets 1.1 or later.
Header: Declared in Winsock2.h.
Library: Use Ws2_32.lib.
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|