| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Jul 09, 2008 12:34 pm Post subject: [C++] concat strings |
|
|
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 |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Wed Jul 09, 2008 12:36 pm Post subject: |
|
|
| Code: |
string str = "con";
str += "cat";
cout << str << endl;
|
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Jul 09, 2008 12:38 pm Post subject: |
|
|
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 |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Wed Jul 09, 2008 12:43 pm Post subject: |
|
|
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 |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Jul 09, 2008 12:50 pm Post subject: |
|
|
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 |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Wed Jul 09, 2008 12:53 pm Post subject: |
|
|
| Can you post some source? But it seems like it could be a unicode porblem. |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Jul 09, 2008 12:54 pm Post subject: |
|
|
| Code: |
char str[100];
strcpy(str,"lol");
strcat(str,"rofl");
SendMessage(hLstPrcs,LB_ADDSTRING,NULL,(LPARAM)str);
|
or if i do it with
it crushes _________________
Stylo |
|
| Back to top |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Wed Jul 09, 2008 1:04 pm Post subject: |
|
|
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 |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Wed Jul 09, 2008 1:16 pm Post subject: |
|
|
| 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
it crushes |
You didn't allocate any memory for str:
| Code: | | char *str = new char[100]; |
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Jul 09, 2008 1:34 pm Post subject: |
|
|
oh thx both SendMessageA worked just fine
and now i know i need to allocate memory to use char*
thx =] _________________
Stylo |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Wed Jul 09, 2008 2:21 pm Post subject: |
|
|
| Just don't forget to delete it after you're done using it. |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Jul 09, 2008 2:31 pm Post subject: |
|
|
i know that in C# i use Dispose(); how can i do it at C++ ? _________________
Stylo |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Wed Jul 09, 2008 2:33 pm Post subject: |
|
|
In your case, you would use:
_________________
- Retired. |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Wed Jul 09, 2008 3:47 pm Post subject: |
|
|
| If you use string you can use string.c_str(); |
|
| Back to top |
|
 |
|