| |

VerySource

 Forgot password?
 Register
Search
View: 765|Reply: 2

Space before the string

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-9 10:30:01
| Show all posts |Read mode
Is there any function that can add spaces before the string.
as follows:
char * p = "hello";
The result is:
p = "hello";
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-4-3 17:45:01
| Show all posts
strcat, but pay attention to allocate enough memory.
Reply

Use magic Report

1

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-4-9 10:00:02
| Show all posts
char * p = "hello";
* The content of * p cannot be changed. The c-style string is const here, so you must use p to point to a block of memory
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <iostream.h>
using namespace std;

main ()
{
char * p = "hello";
char * q;
q = new char (10);
q [0] = 0x20;
q [1] = 0x00;
strcat (q, p);
p = q;
cout << p << endl;
system ("pause");
delete q;

}
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