metMetin is a pointer to TCHAR. So you cannot use the + operator for it. You should use the strcat() to append "abc" to metMetin.
In other words, I believe metMetin is a c-string, not a C++ string, so no overloaded + operator is provided.

11-01-2008

flashbaz-pi

Oh man, thanks a lot! This is exactly what I need.

Note: To use StrCat() function, program needs shlwapi.h header. That means U must add

Code:

#include <shlwapi.h>

to beginning of code.

11-01-2008

Elysia

Quote:

Originally Posted by C_ntua

In other words, I believe metMetin is a c-string, not a C++ string, so no overloaded + operator is provided.

You do need to believe. It is a C-style string (TCHAR*).However, it being a pointer, you should not append any characters to it.http://cpwiki.sourceforge.net/Common...kes_and_errors
Instead, the best way to do this would be to make it std::string instead. Then you can use operator + as normal.
But then again, since metMetin is undefined from the beginning (if it is a pointer), plus contains nothing, it would be better to do only an assign and not an addition with operator +. metMetin is also a local variable so there is no chance it could contain anything else.

And strcat is a C API, not a Windows API, so shlwapi.h is unnecessary. You should be including string.h to use it. But then again, you should not use it at all, since this is C++.

11-02-2008

flashbaz-pi

strcat() is a C API, right. But StrCat() is a Win API. I tried <string.h> and compiler asked for StrCat(). If you use StrCat() in code, compiler needs <shlwapi.h> ! Using StrCat or strcat, it doesn't matter. Bot of them works!

I read the link above. But I couldn't understand how to convert a TCHAR* pointer to a std::string!??

11-02-2008

Elysia

Code:

TCHAR* str;
std::string s = str;

Assuming, you are not using unicode.
And StrCat is Windows API, so it is tied to Windows. When strcat in the C runtime libraries does the exact same thing, this is what you should have been using instead. But regardless, in C++, you should be working with std::string and not char*, wchar_t* or TCHAR*.

11-02-2008

flashbaz-pi

Here is the problem: I convert TCHAR to std::string. That's ok. But when I

Due to conversion operators being unpredictable in the current standard due to implicit conversions, std::string does not include one for const char*, so you have to call the c_str() member function.
The next standard should bring explicit conversion operators to solve this problem, though.

11-02-2008

whiteflags

>> The next standard should bring explicit conversion operators to solve this problem, though.
I have not heard this. If it's more than a rumor, please show me.

Is TCHAR* the same as char*? Wouldn't the .c_str() return a char*, but the MessageBox wouldn't require a TCHAR*. I don't believe there is a problem but just to make sure.

Also, just to mention that you could use strcat(), but you would probably have to copy metMetin contains to a strlen(netMetin+4) buffer and the append "abc" there. But of course this is C++ so a std::string would be much more easy

11-02-2008

Elysia

TCHAR* is either defined as char* or wchar_t* depending if the UNICODE macro is defined. Visual Studio provides project settings for this.
std::string will only work if working with non-unicode, as TCHAR* will then be defined as char*, thus std::string will be able to accept a char* string and MessageBox will be able to take a const char* string (since c_str() returns const char*).
If working with unicode, std::wstring should be used instead.
Unfortunately, there are no "TCHAR" string in the library, but you could easily define one yourself:

typedef std::basic_string<TCHAR> tstring;

11-02-2008

flashbaz-pi

Here is the bombbb! Program crashed!

Code:

std::string metStr = metMetin;

Dev++ compiled this line, but program crached! I'm sure the problem is here. When I push the button which identified as "id_rakam0" the program is crashing.

But that's not last! I want this metMetin as an integer also. Is there any function to do this? Of course must be... But I couldn't find :(

11-02-2008

flashbaz-pi

Here is the bombbb! Program crashed!

Code:

std::string metStr = metMetin;

DevC++ compiled this line, but program crashed! I'm sure the problem is here. When I push the button which identified as "id_rakam0" the program is crashing.

But that's not last! I want this metMetin as an integer also. Is there any function to do this? Of course must be... But I couldn't find :(

11-02-2008

tabstop

Quote:

Originally Posted by flashbaz-pi

Here is the bombbb! Program crashed!

Code:

std::string metStr = metMetin;

DevC++ compiled this line, but program crashed! I'm sure the problem is here. When I push the button which identified as "id_rakam0" the program is crashing.

But that's not last! I want this metMetin as an integer also. Is there any function to do this? Of course must be... But I couldn't find :(

Of course the problem is not there. Unless you're claiming that metMetin is not a null-terminated array of characters? Who knows? (Hint: not us.) EDIT: Actually, reading this again, you've bollixed the call to GetWindowText; so that is what is crashing when you try to write to New Jersey, or wherever metMetin happens to be pointing. You must have actual space on the other end of the pointer metMetin (via malloc/new and friends) before calling the function.

As to the other, you should look into strtol. (Again, you'd have to call it on the .c_str().)