|
Stick^ wrote: But, the article has no directions on how to "install" the .dll addin, and I would like to use it with VS 2005.
Thanks for any help.
Does this help?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi All
I have the below bit of code, it seems that some users somehow are getting the below statement to return TRUE when m_message > 160
can anyone see any problems with this ?
thanks
Simon
int nBytes = lstrlen(m_message);
if (nBytes >160)
{
AfxMessageBox("You have exceeded the maximum number of\ncharacters allowed", MB_ICONSTOP);
return FALSE;
}
else
return TRUE;
|
|
|
|
|
I am not seeing where that would be possible, other than the possibility that m_message is a character buffer (not a string, right?), and there is some other overrun/underrun that is stepping on that buffer...? Or stuffing UNICODE data into a char buffer?
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
sorry should have put that m_message is CString
|
|
|
|
|
If it is a CString , use m_message.GetLength() instead - generally, if an object has a method for some function, you should use it because it may be optimized for that particular object.
Mismanagement of the CString object can also lead to corruption of its data - for example, if you have a reference to that CString someplace that is getting messed around with.
You can also ovverun/underrun heap memory (which the string object uses) by not being too careful with them. If you have any code that casts a CString object into a non-const pointer, that is a good place to start.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
si_69 wrote: m_message is CString
In that case instead of lstrlen, use m_message.GetLength();
nave
|
|
|
|
|
Hi all:
I need to write a function whose signature is:
std::string readWord(ifstream& in);
The function will read one word at a time from "in", and the definition of word is a sequence of alphabetic, apostrophe, hyphen or underscore characters. Anything else is treated as a "white space".
My approach is:
Use fgetc() to read one character at a time from "in", then test it to see if it is a valid character; this procedure will be repeated until the function reads all the characters between two "white spaces".
Any comments is welcome.
Thank you
|
|
|
|
|
an ifstream will only read up to a space anyhow, I would have thought that
string s;
in << s;
return s;
would do it. What you're saying will also work
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Feasible, yes. Optimal, perhaps not. Note that using fgetc(...) with a ifstream object may be troublesome.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
May I ask what would you do if you were trying to accomplish this task?
Thank you
|
|
|
|
|
Christan's approach might work, if you are looking to split a normal string into tokens by normal whitespace (tabs and spaces).
I would need to know more about what you are trying to do in order to offer a possibly more-optimal solution.
For example, if you are building a tokenizer, you might want to build something using (f)lex . If you are counting words in a small file, strtok(...) with a local buffer may work, if using a large file, skipping characters manually with a memory mapped file may work better, etc.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hi James:
"For example, if you are building a tokenizer, you might want to build something using (f)lex. If you are counting words in a small file, strtok(...) with a local buffer may work, if using a large file, skipping characters manually with a memory mapped file may work better, etc."
Your comments are way above my head. I just started learning C++ two weeks ago. Having said that, I do have some knowledge on C programming.
What I try to achieve is simply to produce a "concordance" program using C++. I need to count every word from a text file and make a record of where they are.
First of all, I need to read a word at one time from this text file in the way I described before. I am not so sure now which "string" function I am going to use in order to achieve my goal.
Thank you
|
|
|
|
|
C_Zealot wrote: Your comments are way above my head. I just started learning C++ two weeks ago.
That is OK! :P I sometimes do not understand my audience...
Using Christan's approach may be best for you because it (1) is simple and (2) it works (well enough).
I am not sure how his example will handle punctuation, so be aware. In other words, I do not know if the following string:
This is a simple-string, I think... Will return 6 items:
This is a simple-string, I think... -Or 12 items:
This is a simple - string , I think . . . -Or some value in between. You will need to experiment to make sure it is working correctly for your needs. I am guessing that it will only react to spaces and return 6, and I think that behavior can be changed, but always best to make sure...
Good luck!
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
C_Zealot wrote: Your comments are way above my head. I just started learning C++ two weeks ago. Having said that, I do have some knowledge on C programming.
Then stick with what you have, whether it is optimal or not. Making code optimal and efficient will come with time and experience. Get you logic down and make it understandable.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
#include < iostream >
#include < string >
using namespace std;
ifstream in("myfile.txt", ios::in);
if(in.good())
{
string strWord;
while(!in.eof())
{
strWord << in;
}
}
Something like that should work for what you want to do. You can even change the ifstream to split on something other than whitespace by calling one of it's functions.
See this for more reference:
http://www.cplusplus.com/reference/iostream/ifstream/[^]
Just noticed you wanted this function prototype:
std::string readWord(ifstream& in)
{
string s = "";
if(in.good())
{
s << in;
}
return s;
}
|
|
|
|
|
hai,
Any one please tell how to get the position in integer values of selected item in ClistControl
Thanks In Advance
Jannath
|
|
|
|
|
int index=m_List.GetNextItem(-1,LVNI_SELECTED);
|
|
|
|
|
|
|
Since you mention values and not value, I am presuming that you are looking for multiple selected items, so I would recommend using CListCtrl::GetFirstSelectedItemPosition(...) and CListCtrl::GetNextSelectedItem(...) .
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
i mean a single value.i am selecting a single value & i want the exact position of that item in the list
Thanks in Advance
|
|
|
|
|
Whitesky's approach is more direct and will work well, but note that my above will also work for single selected items (or for nothing selected as well).
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Your answer is perfect.
|
|
|
|
|
On a button press in dialog i am Creating a thread by the statement
pTh = new CMyThread;
Where CMyThread is CWinThread derived class and pTh is declared in the MyDialg.h as
CMyThread *pTh
Even though i close the dialog can my thread run without any issues. Are there any points that i should note in this senario.
Thank you.
KIRAN PINJARLA
|
|
|
|
|
jup, the Thread is still alive
you should kill him in the OnClose-Method via pTh->PostThreadMessage(WM_QUIT);
|
|
|
|