|
mcsherry wrote: myList.end()
you'd probably want myList.end()-1 there, since myList.end() isn't an element.
otherwise, that should do what you want.
or, you can use pop_back / push_front
|
|
|
|
|
Chris Losinger wrote: i'd recommend a std::list
Or a deque[^]
|
|
|
|
|
mcsherry wrote: I currently use a vector to store a set of records. However there is now a limit to the number of elements the vector contains and once it is filled we have to remove the first element and insert the new one at the back. But as an added complication we aren't allowed any dynamic memory allocation so what needs to be done is:
1) Remove first element from list but do not free it's memory
2) overwrite the removed elements data with the new data
3) insert the updated element to the end of the vector
What is the best way to do this? I am not limited to only storing the data in a vector so if any other containers are more suitable then let me know!
I don't think STL provides any class that specificly avoids dynamic memory allocation, but ther is the notion of an allocator class which could be designed to just manage members of a fixed sized array. It might be simpler to not use an STL container. Boost might have the kind of class your looking for.
Failing that, you could implement your own class that does this. It would require an array, a first element index, and either a last element index of a content count. When the array gets full, you could update the first element index and assign a new value to the former first element.
Nathan
|
|
|
|
|
Well first off you are using dynamic memory just by using the ‘vector’ class, or any other STL collection, to store your records. Whether or not is frees the memory used by the first element is another story, it may just move the other elements down by one address, making the previous last element space empty (break out the pencil and paper). If the implementation of the ‘vector’ you are using does that, then you can simply remove the first element and add the new element to the end, and you have met the requirement (no special coding required); provided your class does not allocate memory in its copy constructor.
If you were dealing with a situation where you are supposed to write your own ‘vector’ type class, then I would say that instructor wants you to learn about ‘in place’ construction (look it up) using ‘new”.
Sorry if that did not help, but it is something you need to examine in detail to understand.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Hi
I have created a toolbar for IE in ATL,COM and WTL without using MFC.Now I want to get notification whenever the user changes the URL in the address bar or does a page refresh.I am using BeforeNavigate2 function which is working properly for any URL change,but not working for page reload or refresh.I need to get notified whenever there is a page refresh and whenever there is a navigation to different page.How to get it?
|
|
|
|
|
can any one send me the code for sending sms to mobile from aspx.cs code in c# code
|
|
|
|
|
me to want same coding . if u got it send to my mail plz..
by
vadivelu
9940294388
chennai
|
|
|
|
|
hi all
I have problem im my program,
I have:
<br />
string str_1, str_2;<br />
if( strcmp(str_1.data(),str_1.data()) == 0)<br />
{<br />
cout<<"equals";<br />
}<br />
else<br />
{<br />
cout<<"Not equals";<br />
}<br />
problem is that in 'str_1' and 'str_2' I have same text and rezult is "Not equals", can you help me and say how can I compeer two STL string's?
|
|
|
|
|
Hello,
If you refer to your STL implementation doc's, you should find that data(): "Returns a pointer to an array of characters, not necessarily null-terminated, representing the string's contents", so it's probably a bad idea to pass that to a function that expects 0-terminated 'strings'. You should use c_str() instead, if you want to use strcmp.
A better way, if you're just testing for equality, would be to use std::string's operator ==(), as in
if (str_1 == str_1)
HTH
Jonas
---
"Man will never be free until the last king is strangled with the entrails of the last priest". -- Denis Diderot
|
|
|
|
|
<br />
if (str_1 == str_1)<br />
?
there is not operator ==()
|
|
|
|
|
If you're using STL's std::string there is indeed an operator == .
Steve
|
|
|
|
|
In your example code you write
if( strcmp(str_1.data(),str_1.data()) == 0)
so I just went with the same comparison.
std::string has the == operator, please refer to your documentation. If your implementation doesn't, consider updating to a proper implementation.
You can also use str_1.compare(str_1) (or str_2 if it's just a type-o)
/J
---
"Man will never be free until the last king is strangled with the entrails of the last priest". -- Denis Diderot
|
|
|
|
|
thanks.
it help me.
|
|
|
|
|
Don’t do that! If you want to compare two string object use “str_1 == str_2”.
If you must use the C comparison function then use “strcmp(str_1.c_str(), str_2.c_str())”.
Of course the example you are giving will always be true, provide the system does not object, because both arguments are the same.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
TCHAR buffer [16384];
DWORD bufferSize = sizeof(buffer)/sizeof(buffer[0]);
BOOL bRes = InternetGetCookie(("http://www.codeproject.com"), NULL, (LPWSTR)buffer, &bufferSize);
DWORD ret;
if(bRes==FALSE)
{
ret = ::GetLastError();
CString str;
str.Format(_T("%d"),ret);
MessageBox(NULL,str,NULL,MB_OK);
MessageBox(NULL,_T("no items1"),NULL,MB_OK);
if (ret == ERROR_NO_MORE_ITEMS)
MessageBox(NULL,_T("no items"),NULL,MB_OK);
else if(ret == ERROR_INSUFFICIENT_BUFFER)
MessageBox(NULL,_T("insufficient buffer"),NULL,MB_OK);
else if(ret == ERROR_INVALID_PARAMETER)
MessageBox(NULL,_T("invalid parameters"),NULL,MB_OK);
}
else
{
MessageBox(NULL,buffer,NULL,MB_OK);
}
This code is displaying garbage value for buffer.But I need the cookie value.what to do?
|
|
|
|
|
rindam wrote: what to do?
First, stop posting your question multiple times.
Second, a previous reply already told you the data is encoded and gave you a link to read. If you want to develop software I suggest you stop typing questions into forums and start reading the documentation that is relevant to your task.
|
|
|
|
|
LPCSTR name="usrauth"; //name of the cookie
TCHAR buffer [16384];
DWORD bufferSize = sizeof(buffer)/sizeof(buffer[0]);
BOOL bRes = InternetGetCookieA(("http://www.mirracle.com"), name, (LPSTR)buffer, &bufferSize);
MessageBox(NULL,buffer,NULL,MB_OK);
This above code I am using to get the cookie value.But messagebox is not displaying the cookie value,it is displaying some garbage value.How to get the cookie value here?what is the mistake here
|
|
|
|
|
C:\Documents and Settings\'user'\Cookies
in this folder ise cookie-s in text files sow you can read cookies in noteped
"where the bar should change according to whether the user is logged in or logged out."
if cookie is set user is logged in and if it is't set he is logged out.
you must know that cookies have life time.
Example:
some cookies are deleteing wen you logged out, but some cookies "live" 50 minute( mail.ru example) or more.
in my site I am deletin cookies when user logged out.
|
|
|
|
|
InternetGetCookie function is always returning false.I am giving u the code here,can u plz tell me where the mistake is?
-------------------------------------------------------------------------------
char szURL[256]="http://www.mirracle.com";
LPWSTR lpszData = NULL; // buffer to hold the cookie data
DWORD dwSize=255; // variable to get the buffer size needed
LPCWSTR usrauth =NULL;
BOOL result=InternetGetCookie(szURL,usrauth,lpszData,&dwSize);
DWORD ret;
if(result==FALSE)
{
ret = GetLastError();
if (ret == ERROR_NO_MORE_ITEMS)
MessageBox(NULL,_T("no items"),NULL,MB_OK);
else if(ret == ERROR_INSUFFICIENT_BUFFER)
MessageBox(NULL,_T("insufficient buffer"),NULL,MB_OK);
else if(ret == ERROR_INVALID_PARAMETER)
MessageBox(NULL,_T("invalid parameters"),NULL,MB_OK);
}
else
{
MessageBox(NULL,lpszData,NULL,MB_OK);
}
The InternetGetCookie function is always returning false here and I am not being able to get the cookie value for this particular site.Plz help me.
|
|
|
|
|
The way you've specified the output buffer is wrong - YOU have to allocate that buffer - the function won't do it for you. At the moment, you're telling th efunction to put teh cookie data at address zero - always a bad idea.
This code seems to work (OK, I've used a different URL - just replace mine with yours):
TCHAR buffer [16384];
DWORD bufferSize = sizeof(buffer)/sizeof(buffer[0]);
BOOL bRes = InternetGetCookie(_T("http://www.codeproject.com"), 0, buffer, &bufferSize);
|
|
|
|
|
here also this function is returning false.whats the problem?
|
|
|
|
|
I have tried with the below code:
TCHAR buffer [16384];
DWORD bufferSize = sizeof(buffer)/sizeof(buffer[0]);
BOOL bRes = InternetGetCookieA(("http://www.mirracle.com"), name, (LPSTR)buffer, &bufferSize);
this code is working fine .but I need to get the cookie value,How can I get it?
|
|
|
|
|
The string in buffer is the value. It's stored in an encoded form, as described here[^]
|
|
|
|
|
Hi,
I would like to use bitwise operators (specifically, & and |) on a pair of std strings of equal length. At the moment I am simply iterating through both strings and carrying out the operation on each byte individually. However this seems a little inefficient to me, and I would prefer to use the bitwise operator on the whole string, as a chunk of memory.
Is it possible? Is there a more efficient way of doing it that iterating through the strings? The strings in question are quite long, a few thousand bytes.
Thanks for any ideas
Mick
|
|
|
|
|
mellib wrote: However this seems a little inefficient to me, and I would prefer to use the bitwise operator on the whole string, as a chunk of memory. mellib wrote: Is there a more efficient way of doing it that iterating through the strings?
The only efficiency you'll gain is in lines of code - the performance would be exactly the same - the only way you can apply a bitwise operator to a memory range is to iterate through it. You could iterate through the strings a longword at a time instead of a byte (although the only way of doing that probably makes unwarranted assumptions about std::string implementation details).
Seriously - measure the performance and determine if it has a serious impact on your code before trying to optimise.
|
|
|
|
|