Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] concat strings

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Jul 09, 2008 12:34 pm    Post subject: [C++] concat strings Reply with quote

how can i concat strings in c++, since the "+" doesn't work i figured that there's a function for that like compare so i tried strcat but the window crushes anytime i active it
_________________
Stylo
Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Wed Jul 09, 2008 12:36 pm    Post subject: Reply with quote

Code:

string str = "con";
str += "cat";
cout << str << endl;
Back to top
View user's profile Send private message AIM Address MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Jul 09, 2008 12:38 pm    Post subject: Reply with quote

strings in C++ aren't defined like that :S or i'm missing something here , it's an array of chars ?!?!
_________________
Stylo
Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Wed Jul 09, 2008 12:43 pm    Post subject: Reply with quote

Uhm.. The string class is part of the standard library.

http://www.cplusplus.com/reference/string/string/


For char array strings you can do strcat(destination, source)

Code:

char str[100];
strcpy( str, "con" );
strcat( str, "cat" );
cout << str << endl;
Back to top
View user's profile Send private message AIM Address MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Jul 09, 2008 12:50 pm    Post subject: Reply with quote

i'm putting the strings inside a listbox not a console
and now i see █████ when i add the string to the listbox :S ?!!?

_________________
Stylo
Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Wed Jul 09, 2008 12:53 pm    Post subject: Reply with quote

Can you post some source? But it seems like it could be a unicode porblem.
Back to top
View user's profile Send private message AIM Address MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Jul 09, 2008 12:54 pm    Post subject: Reply with quote

Code:

char str[100];
strcpy(str,"lol");
strcat(str,"rofl");
SendMessage(hLstPrcs,LB_ADDSTRING,NULL,(LPARAM)str);

or if i do it with
Code:

char *str;
// etc

it crushes

_________________
Stylo
Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Wed Jul 09, 2008 1:04 pm    Post subject: Reply with quote

If you do the *str then you're passing a pointer to a pointer to the listbox control instead of a pointer to a char array.

I'm not sure why you're having a problem though, try using SendMessageA instead maybe?
Back to top
View user's profile Send private message AIM Address MSN Messenger
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Wed Jul 09, 2008 1:16 pm    Post subject: Reply with quote

1qaz wrote:
Code:

char str[100];
strcpy(str,"lol");
strcat(str,"rofl");
SendMessage(hLstPrcs,LB_ADDSTRING,NULL,(LPARAM)str);


Maybe your compiler's default character set is unicode?
Then call SendMessageA. (You can change the default character set at settings, Alt+F7 -> Configuration Properties -> General -> Character Set)

1qaz wrote:
or if i do it with
Code:

char *str;
// etc

it crushes

You didn't allocate any memory for str:
Code:
char *str = new char[100];
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Jul 09, 2008 1:34 pm    Post subject: Reply with quote

oh thx both SendMessageA worked just fine
and now i know i need to allocate memory to use char*
thx =]

_________________
Stylo
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Wed Jul 09, 2008 2:21 pm    Post subject: Reply with quote

Just don't forget to delete it after you're done using it.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Jul 09, 2008 2:31 pm    Post subject: Reply with quote

i know that in C# i use Dispose(); how can i do it at C++ ?
_________________
Stylo
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Wed Jul 09, 2008 2:33 pm    Post subject: Reply with quote

In your case, you would use:

Code:
delete[] str;

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Jul 09, 2008 2:34 pm    Post subject: Reply with quote

thank you Very Happy
_________________
Stylo
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Jul 09, 2008 3:47 pm    Post subject: Reply with quote

If you use string you can use string.c_str();
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites