| |

VerySource

 Forgot password?
 Register
Search
View: 1053|Reply: 6

How do the two LPCTSTR values ​​add up?

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-31 21:00:01
| Show all posts |Read mode
How do the two LPCTSTR values ​​add up?
E.g
LPCTSTR a1 = _T ("a");
LPCTSTR a2 = _T ("a2");
LPCTSTR a3;

How to add a1 and a2 to a3

Thank you:)
Reply

Use magic Report

0

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-18 22:15:01
| Show all posts
strcat
wcscat
Reply

Use magic Report

0

Threads

36

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 Singapore

Post time: 2020-3-21 20:15:01
| Show all posts
#include <string>

std :: basic_string <TCHAR> s1 = a1;
std :: basic_string <TCHAR> s2 = a2;
std :: basic_string <TCHAR> s3 = s1 + s2;
LPCTSTR a3 = s3.c_str ();
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 11:15:02
| Show all posts
strcat (a1, a2); //string concatenation function
a3=a1;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 11:30:01
| Show all posts
strcat (a1, a2);
a3=a1;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 12:30:01
| Show all posts
Never use strcat, because strcat will modify the content of a1, which means that the first parameter must not be const.
Note that your string is a constant pointer and it points to a string constant. The data stored in the constant area cannot be modified.
And your a3 has no allocated space at all.
First, a3 should be defined as LPTSTR, otherwise it is a constant and cannot be modified. Then use:
a3 = (TCHAR *) malloc(255 * sizeof(TCHAR));
strcpy (a3, a1);
strcat (a1, a2);
That's it.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 12:45:01
| Show all posts
a3 = CString(a1) + a2;
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list