编写一个程序,链接两个字符串字面常量,将结果保存在一个动态分配的char数组中,重写这个程序,连接两个标准string对象
#include <iostream>
#include <Windows.h>
#include <string>
#include <stdio.h>
using namespace std;
int main(void)
{
string a="hello!";
string b="world";
string s="";
s=a+b; //连接两个字符串到s
char *c=new char[s.length()]; //动态分配
for(int i=0;i<s.length();i++)
{
*(c+i)=s[i];
}
for(int i=0;i<s.length();i++)
{
cout<<*(c+i);
}
delete[] c;
system("pause");
return 0;
}
浙公网安备 33010602011771号