|
Hi
How to replace occurance of one particular character in a string
For ex String str1 = "test_string_one"
In above string there are 3 occurance of character 't' at position 0,3 and 6
say i want to replace this 't' with 'z' so my string becomes as
"zesz_szring_one"
How to do it in C++ in one line without any looping or with looping
|
|
|
|
|
The CString class has a Replace method that will do this.
|
|
|
|
|
Replace(wchar_t oldChar, wchar_t newChar)
--
"Programming is an art that fights back!"
|
|
|
|
|
If you want to do it with standard C++ then use std::replace:
std::string str1( "test_string_1" );
std::replace( str1.begin(), str1.end(), '_', '-' );
FREX converts all the underscores to dashs.
Cheers,
Ash
|
|
|
|
|
Hi,
In my MDI application,i have one Group view with more No of views.I will get every page by using PageUp and PageDown.
So i coded in OnKeyDown() to get this function.
But when i press PAGEDOWN or PAGEUP,it doesnot go to that function part.But when i press like
SHIFT+PAGEDOWN it works.
So i use PreTranslateMsg() coding,i copied same coding form OnKeyDown(),but when i press PAGEDOWN it works but it move to 3rd page not 2nd page.It goes like 3,5,7 page.
When i use Mouse roll it works fine in OnKeyDown().
void CGroupView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar == 17)
return;
BOOL bMax;
CView *curView;
CMDIFrameWnd *fWnd = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *fChWnd = fWnd->MDIGetActive(&bMax);
if(fChWnd->GetSafeHwnd())
curView = (CView *)fChWnd->GetActiveView();
else
curView = NULL;
switch(nChar)
{
case 33:
{
giGrPNo--;
if(giGrPNo<1)
giGrPNo=1;
else
{
Invalidate(FALSE);
}
iTagNo = -1;
break;
}
case 34:
{
giGrPNo++;
if(giGrPNo > iGrpCnt)
giGrPNo = iGrpCnt;
else
{
Invalidate(FALSE);
}
iTagNo = -1;
break;
}
}
BOOL CGroupView::PreTranslateMessage(MSG* pMsg)
{
UINT nChar = (UINT)pMsg->wParam;
UINT nKeyDown = (UINT)pMsg->lParam;
<..Same coding from OnKeyDown()..>
}
When i press PAGEDOWN it should go to that function part.What can i do?
Anu
|
|
|
|
|
Anu_Bala wrote: So i use PreTranslateMsg() coding,i copied same coding form OnKeyDown()
Possibly you should move the 'same coding' from OnKeyDown to PreTranslateMsg .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ya,
i moved everything form OnKeyDown() to PreTranslateMsg().
It works when i press PAGEDOWN,but it not goes to second page,directly to 3rd page.again if i press PAGEDOWN,it goes to 5th page not to 2nd page.
Anu
|
|
|
|
|
I doubt View switching might be called more than once.
Try using WM_KEYUP
Check documentation for WM_KEYDOWN:
Because of auto-repeat, more than one OnKeyDown call may occur before an OnKeyUp member function call is made. The bit that indicates the previous key state can be used to determine whether the OnKeyDown call is the first down transition or a repeated down transition.
--
"Programming is an art that fights back!"
|
|
|
|
|
I have an application which ejects a USB by CM_Query_And_Remove_SubTree API, but it returns 0x17( CR_REMOVE_VETOED ) error code in XP SP3. But it works fine in XP SP2.
Also please note the below case:
In XP SP3, after I plugged the USB first time after machine start, the USB displayed in explorer, but not able to create/copy a folder\fine into the USB drive.
I have checked with other xp sp3 machine also... issue exists. If I unplug and plug the USB manually then it works. But it works fine in XP SP2 machines.
Could any one please let me know why this issue occurs in xp sp3?
aks
|
|
|
|
|
Hi all,
I want to open a URL(http://10.14.15.23/test/test.aspx) which is present in the server.I am using the following code.
CInternetSession objInetSession;
try
{
CStdioFile* objStdFile = objInetSession.OpenURL("http://10.14.15.23/test/test.aspx",1,INTERNET_FLAG_TRANSFER_ASCII ,NULL,0);
}
catch(CInternetException* exp)
{
exp->GetErrorMessage(lpErr,sizeof(lpErr),NULL);
::AfxMessageBox(lpErr,MB_ICONSTOP);
return 0;
}
Everything is working fine. But, the server local user account, which is configured in IIS for anonymous access, gets locked frequently. So, i am not able to access this link.
Server machine has a policy that if we enter wrong password for more than 4 times while logging,the user account will get locked.
Can anyone please tell me the reason for this user account lock?
Thanks,
modified on Tuesday, June 1, 2010 2:54 AM
|
|
|
|
|
Use either Netmon or Wireshark to capture the network traffic to make sure the credentials are NULL.
Check the IIS log files and look for the 403 responses as these should contain the credentials that were actually used for the request.
However the first thing to check is the application pool the ASPX is running in and what credentials the server will use to run the request.
If you enable auditing on the test.aspx file you will see from the security event log which credentials are being used.
Put simply the site you have created is not as anonymous as you think so always check with a browser first before coding against it. If you cannot access the link then how is your code.
hope that helps.
Alan
|
|
|
|
|
No i just want to know that system user account lock issue is bcoz of this code?
|
|
|
|
|
Enable auditing. It is the only way...
This should help but if you search the Microsoft KB for "Account lockout" there are plenty of instructions on how to do it.
http://support.microsoft.com/kb/921469[^]
Alan
|
|
|
|
|
HI,
Please clarify my doubt.
How many maximum Documents and View will be available in SDI ?
How many maximum Documents and View will be available in MDI ?
Thanks,
Krishna
|
|
|
|
|
The number of documents and views are limited only by memory.
The documents and its views in an MFC application are stored internally in linked lists.
So you shouldn't worry about this.
If you have reached the limit and are unable to add more, there is something seriously wrong with the program and needs a re-design.
|
|
|
|
|
That's true for MDI but for an SDI, you only have one document.
|
|
|
|
|
Thanks Cédric,
1.In SDI only one Document will be there or one Document at a time we can load ?
2.How many views in SDI is one View or Many ?
Thanks,
Rayalu
|
|
|
|
|
1. I don't get your question. In a SDI application, you can only have one document loaded at a time in memory. Of course, you can load another document but then the old document is replaced by the new one. You always work with only one document. Does that answer your question ?
2. As many as you like (and what the memory allows).
|
|
|
|
|
Thank you Cedric,
Same thing i asked.You answered my question.
Thanks,
Krishna
|
|
|
|
|
Unless you want to do some real fancy footwork you can only have one document in an SDI application. This is due to the limitation of only having one frame window per instance of the application with MFC out of the box. There are ways you could get 'round this but they're probably not worth doing. With MDI apps you can have as many frame windows as you want so as many documents as you can fit in memory.
You can have as many views per document as you want with the limitations of what can fit on your screen.
Cheers,
Ash
|
|
|
|
|
SDI is short for Single Document Interface, MDI for Multiple Document Interface. So that's that. As for views, you can have as many as you like as long as they fit into memory. You can even have more than can be shown at a time on screen if you'd like, since you can dynamically change what views you want to be visible.
|
|
|
|
|
Means for SDI i have only one Document, But i can have any no of views ?
Thanks,
Krishna
|
|
|
|
|
Mr.Cedric
Answered my Question Thanks once Again guys.
Krishna
|
|
|
|
|
I have it down to one error I can not fix
here it is
Error 1 error C2660: 'CBaseEntity::isFaceing' : function does not take 1 arguments C:\Users\Josh\Desktop\pXi_r1430\src\CZoneHandler.cpp 356 1 PXI<br />
Here is the code in question
if(mob->hasBehaviour(AGGRO_SIGHT) && mob->isFaceing(schar->loc.p)) {
if((CUtil::distance(schar->loc.p, mob->loc.p) <= 15 )) {<br />
mob->aggroChar(schar);<br />
Here is the function ( I think tis what it is called )
bool CBaseEntity::isFaceing(struct position p, int coneAngle) {<br />
<br />
unsigned char truerot = (unsigned char)this->getRot();<br />
<br />
if((p.x - this->loc.p.x) == 0) { <br />
p.x += 0.001f;<br />
}<br />
<br />
if((p.z - this->loc.p.z) == 0) { <br />
p.z += 0.001f;<br />
}<br />
<br />
float angle = atan2((p.z - this->loc.p.z),(p.x - this->loc.p.x));
unsigned char rot = (unsigned char) ((2 * 3.14159265358979f - angle) * 256 / (2 * 3.14159265358979f));
<br />
unsigned char diff = (unsigned char) (abs(truerot - rot));
<br />
if(diff <= coneAngle || diff >= (256 - coneAngle)) {
return true;
}<br />
<br />
return false;
<br />
}<br />
Any help here is greatly appreciated
|
|
|
|
|
It seem to me the compiler is telling you exactly what's going wrong.
The function CBaseEntity::isFaceing is defined as follows:
bool CBaseEntity::isFaceing(struct position p, int coneAngle)
I have underlined it's two parameters.
You're calling it like this:
mob->isFaceing(schar->loc.p)
Here your only using one parameter.
Steve
|
|
|
|