|
you should tokenize the string with a delimiter of your choice, then append the tokens back into your string.
// code for tokenizing, taken from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html[^]
void Tokenize(const string& str,
vector<string>& tokens,
const string& delimiters = " ")
{
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}
|
|
|
|
|
Thanks!
understood!
|
|
|
|
|
have u tried strstr() of the string.h ?....itz used to find a string inside a srring!!!!!
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
now thats a useful info!
|
|
|
|
|
|
yeah I know, but I was looking for string, not CString.
but, I don't quite understand the difference between the two.
I know that CString is microsoft's string class, and it has more functionality, but what are the disadvantages of CString comparing to string?
|
|
|
|
|
|
i've checked the string class, and it also contains a replace member function, so essentially you can do the same thing that alok said for the CString class.
anyway here's more definitions for the string class: http://www.cppreference.com/cppstring/[^]
|
|
|
|
|
ng kok chuan wrote:
anyway here's more definitions for the string class: http://www.cppreference.com/cppstring/[^]
Looks Good Thanks
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hey need some help here
here's my code (partial)
class CMyClass : public CDialog
{
public:
HANDLE thread_handle;
DWORD thread_id;
UINT ThreadFunc(LPVOID data);
// other things
}
then
thread_handle = AfxBeginThread(ThreadFunc,
// (LPVOID)1,THREAD_PRIORITY_NORMAL, 0,0,NULL);
no the problem is i get this error
error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
why am i getting that error.. also when i use the api method CreateThread it also produces an error saying that CreateThread cannot convert parameter 3 from unsigned long (void*) to unsigned long (__stdcall)(void*) or something like that... I really need to get this thread running for my program....
|
|
|
|
|
The thread function has to be declared static . This is because the compiler needs to determine its address, which won't be known until runtime otherwise.
|
|
|
|
|
I'm just writing to back up that other answer. It's true you do need to delcare static. Sometimes though, that can be a problem becuase you want to access member variables and functions back in CMyClass. Here's a good way to get what you want here, I think:
class CMyClass : public CDialog
{
public:
HANDLE thread_handle;
DWORD thread_id;
static UINT ThreadStartFunc(LPVOID data);
UINT ThreadFunc();
} and then...
thread_handle = AfxBeginThread(ThreadStartFunc, (LPVOID)this); then later:
UINT CMyClass::ThreadStartFunc(LPVOID data)
{
ASSERT(data != NULL);
return ((CMyClass*)data)->ThreadFunc();
}
UINT CMyClass::ThreadFunc()
{
return 0;
} I don't know if that helps at all.
Joel Holdsworth
Wanna give me a job this summer?
Check out my online CV and project history[^]
|
|
|
|
|
Thanks.... it's working now... now i'm on to the final stage..
|
|
|
|
|
|
Joel Holdsworth wrote:
thread_handle = AfxBeginThread(ThreadStartFunc, (LPVOID)this);
Friend, you are breaking the cardinal rule of MFC, CWnd objects are not allowed to be passed between threads, it should only be used by the thread which created it. You will never be able to predict when the application bombs in your case. Please have a look into this link
q147578/[^]
suhredayan There is no spoon.
|
|
|
|
|
True... you're right! I wasn't thinking. I never create thyreads in window objects! I always have a dedicated class to administrate my worker or back-end or whatever.
Joel Holdsworth
Wanna give me a job this summer?
Check out my online CV and project history[^]
|
|
|
|
|
Joel Holdsworth wrote:
I never create thyreads in window objects! I always have a dedicated class to administrate my worker or back-end or whatever.
Can't say anyhting without seing your administrator class
suhredayan There is no spoon.
|
|
|
|
|
This is covered in the FAQ:
http://www.codeproject.com/cpp/cppforumfaq.asp#cpp_callbacks
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
i'm writing a header file and i have the following code:
public:
...
private:
T arr[]; // when i compile it tells me that it is an illegal zero-sized array
what i dont understand is that i works fine on a linux compiler, so what does zero-sized array mean
alex
|
|
|
|
|
its not a bug.. you have to specify the size of an array or dynamically allocate it.. the size can't be unknown
|
|
|
|
|
it isn't safe for linux to allow that actually. imo what vc++ did is correct.
anyway if u want a zero-sized array, do u mean u're going to allocate memory to the array on the fly?
if so, u should declare it as a pointer. i.e.
T *ptr;
then u should use new and delete to alloc and free the memory respectively.
even better, use vectors as it does all the memory handling for u.
http://www.roguewave.com/support/docs/sourcepro/stdlibref/vector.html[^]
|
|
|
|
|
Hi there,
How can I copy a folder to a different location. I tried using the SHFileOperation but it did not work.
Thanks!
|
|
|
|
|
It's hard to say without posting your code.
A common problem is failing to append the extra NULL character to from and to buffers.
You can try this and see if it works for you:
http://www.thecodeproject.com/shell/cshellfileop.asp
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Post the code which is not working.
suhredayan There is no spoon.
|
|
|
|
|
i want that my application should start when the computer start like time in tray of taskbar.
ddd
|
|
|
|