|
Use std::sort from the STL. For example to sort an array of int s:
int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5};
int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]);
std::sort(NumArray, pNumOnePartEnd);
Remember to #include <algorithm> .
Steve
|
|
|
|
|
Stephen Hewitt wrote:
int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5};
int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]);
std::sort(NumArray, pNumOnePartEnd);
should probably be pNumOnePastEnd
|
|
|
|
|
Yes, I did mean to write "one past the end". Note however that I made the mistake consistently so the example would still work.
Steve
|
|
|
|
|
Hi again guys
i have a strange problem.
i'm reading from a file character by character and i'm pushing the characters into a queue like this
<br />
do{<br />
c = getc (pFile);<br />
plainText.push(c);<br />
} while (c != EOF);<br />
so far so good then i copy the content of the queue into a string but i try to remove all unessesary spaces
<br />
string text;<br />
while (!PlainText.empty()) <br />
{<br />
if (PlainText.front()!=' ')<br />
{<br />
Plain_Text+=PlainText.front();<br />
PlainText.pop();<br />
}<br />
else if(PlainText.front()==' ')<br />
{<br />
while(PlainText.front()==' ' && !PlainText.empty() )<br />
{<br />
PlainText.pop();<br />
}<br />
Plain_Text+=" ";<br />
}<br />
<br />
}<br />
I'm not sure if i made my self clear so i'll give you an example.
lets say i have this writen in a file
<br />
This is writen in<br />
a text file but with more than one <br />
spaces in between the words
i want to copy the contents of this file into the string
but in this form
This is writen in a text file but with more than one spaces in between the words
My code doesn't make any changes it lives all the spaces as they where
any ideas pls help
Thanks a lot
-- modified at 6:13 Sunday 11th June, 2006
|
|
|
|
|
you didn't mention what type is your queue ? write here the definition of the queue
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
thanks for the reply my queue is of type char
queue<char>PlainText;
|
|
|
|
|
Do you want to convert a multiline string into a single line one. Although you talk about removing extra spaces but from the example it seems you want to remove newline ('\n') character.
-Saurabh
|
|
|
|
|
Hey thanks for the reply
yes i also whant to remove newline but spaces in between as well the example is not clear because when i post the message my spaces where removed.
|
|
|
|
|
antonaras wrote: ...when i post the message my spaces where removed.
Use ampersand nbsp; in your post.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
I have created a small project in vc++6 with a editable list control. I took the help of some of the articles found here.
I wanted the listview's edit box to have some background colour when that box is being edited. I intergrated another class I found in CodeProject. But the box doese'nt behave properly. I do not know how to correct it, or what I should change.
Can somebody help me out. I can e-mail the project to you so that you can see it and tell me what I must add or change.
Thanks.
Tara
Fortitudine Vinsinues!
|
|
|
|
|
use WM_CTLCOLOREDIT message in your class(derived CListCtrl) and use
<br />
HDC hdc=(HDC)wParam)<br />
::SetBkColor(hdc,RGB(53,197,200));<br />
whitesky
|
|
|
|
|
I have added that to the class. But this is what is happening:
When I click on a cell in the listview the background changes color. After that, when I start typing the color changes back to white and the corners remain yellow...
Please help!
Thanks.
Tara
Fortitudine Vinsinues!
|
|
|
|
|
Hope I understood your question
WM_CTLCOLOREDIT is a message notify
you can see in MSDN(this explain)
"This message notifies the parent window of an edit control when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the edit control."
see this code maybe it is some helpful to you :
<br />
BEGIN_MESSAGE_MAP(CAnswerView,CListView)<br />
ON_MESSAGE(WM_CTLCOLOREDIT, OnColorEdit)<br />
END_MESSAGE_MAP()<br />
...<br />
...<br />
LRESULT CAnswerView::OnColorEdit(WPARAM wParam,LPARAM lParam)<br />
{<br />
HDC hdc=(HDC)wParam;<br />
SetBkColor(hdc,RGB(53,97,200));<br />
SetTextColor(hdc,RGB(255,255,255));<br />
return (LRESULT)m_Brush->m_hObject;<br />
}<br />
whitesky
|
|
|
|
|
pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);
as we know, this is a simple way to create and load the frame with its resouces,
and we notice that the pContext is NULL. And we get a bug:
if pContext is NULL, it will fire CView::OnInitalUpdate Twice!
Here is My explain:
BOOL CFrameWnd::LoadFrame(...)
{
...
if ( !Create(...) ) /// it will fire CView::OnInitialUpdate()
{
return FALSE;
}
...
if ( pContext == NULL )
{
/// it will fire CView::OnInitialUpdate() again
SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
}
return TRUE;
}
So, why these four lines:
if ( pContext == NULL )
{
SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
}
Can anyone help me or fix it?
Thanks!
-- modified at 4:14 Sunday 11th June, 2006
|
|
|
|
|
I am facing problem in finding how can we list all the deleted files in a directory??? I mean is there no way of doing it by some function rather than making a function urself????Can FindFirstFile,FindNextFile can be useful???
|
|
|
|
|
You can enumerate the contents of the Recycle Bin and look at the original location of the files. The only other alternative would be to parse the file system structures (similar to what ScanDisk and NDD do) and look for directory entries marked as deleted. (But even then, the file's data may have been overwritten.)
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
VB > soccer
|
|
|
|
|
See Here[^]maybe it is some helpful to you
whitesky
|
|
|
|
|
Hi All.
I need to know how can i write some function that getting Folder path and return me list of all file in this folder.
The function will be something like this
void func(CString sFolderPath , CString sFileList)
{
...
...
...
While(bFileExist){
sFileList += File.Name;
sFileList += '\n';
bFileExist = FindNextFile(....);
}
}
Thanks for any help.
|
|
|
|
|
use the shell api SHBrowseForFolder once you select a folder use FindFirstFile and then FindNextFile to retrieve all the files under that folder.
hope this helps
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
See
<br />
(1)<br />
TCHAR lpt[260];<br />
lpt[0]='\0';<br />
strcat(lpt,"c:\\");<br />
GetCurrentDirectory(sizeof(lpt),lpt);<br />
DlgDirList(lpt,IDC_LIST2,NULL,DDL_DIRECTORY|DDL_ARCHIVE);
-----------------------------<br />
(2)<br />
WIN32_FIND_DATA find;<br />
HANDLE handle=FindFirstFile("*.*",&find);<br />
while(FindNextFile(handle,&find)!=0)<br />
m_List2.AddString(find.cFileName);
FindClose(handle);
whitesky
|
|
|
|
|
Hey folks!
I'm installing an Internet application which requires a cookie to authenticate. Because it's a low-risk application, I'm using persistent sesssions.
I'd like users to have to enter a login/password to access the service.
There are a bunch of issues with this (checking for valid input, not letting users advance in the installation if they can't enter their login/pass correctly, grabbing the cookie back from the response) and I'd like to know if there are any *free* (not GPL or LPGL) classes or projects, which would allow me to plugin this feature into my application. i.e. i'm looking for login functionality like you might see such as with MSN Messenger.
C++ / MFC is available, but no .NET.
waiting hopefully :P,
chasetoys
-- modified at 2:29 Sunday 11th June, 2006
|
|
|
|
|
I've seen controls that look like Oscopes, Histograms and Volt Meters.... but I am looking for one that looks like a thermometer to report back temperarture... for use in C++/MFC application
Does anyone have any like that or can point me to something.
Regards and thanks in advance
Pierre
|
|
|
|
|
|
Those are slider controls... not thermometers
but thanks for trying
Regards
Pierre
|
|
|
|
|
pblais wrote: I've seen controls that look like Oscopes, Histograms and Volt Meters.... but I am looking for one that looks like a thermometer to report back temperarture...
That is something that looks like a thermometer.
If you couldn't find what you want, it shouldn't be too hard to modify it so that it reports temperature.
- It's easier to make than to correct a mistake.
|
|
|
|