给字符串前加空格
请问有什么函数可以给字符串前加上空格.
如下:
char* p= "hello ";
结果要为:
p= " hello ";
[解决办法]
char* p= "hello ";
*p的内容是不能改的,c风格字符串在这里是const的,所以你要用p指向令一块内存
#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;
}