6.3w+
社区成员
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string word;
cout<<endl<<"请输入字符串: ";
cin>>word;
const int len=strlen(word.c_str());
char *ic=new char[len]; //这里是否应该为[len+1]?
char *pic=ic; //创建指向指针的指针
for (string::iterator i=word.begin();i!=word.end();++i,++pic)
*pic=*i; //将字符串中的元素置入动态数组
for(char *p=ic; p!= ??? ;++p) //遍历动态数组
cout<<*p<<endl; //输出数组中的元素
delete [] ic;
system("pause");
}
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string word;
cout<<endl<<"请输入字符串: ";
cin>>word;
const int len=strlen(word.c_str());
char *ic=new char[len];
char *pic=ic;
for (string::iterator i=word.begin();i!=word.end();++i,++pic)
*pic=*i;
for(char *p=ic;p!=ic+len;++p) //这样处理 lz满意吗?
cout<<*p<<endl;
delete [] ic;
system("pause");
return 0;
}
for(char *p=ic; p!= pic ;++p) //遍历动态数组 pic可以实现啊 这么简单啦!pic到字符数组的末尾了。
cout <<*p <<endl;
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string word;
cout<<endl<<"请输入字符串: ";
cin>>word;
const int len=strlen(word.c_str());
char *ic=new char[len+1]; //长度[len+1]
char *pic=ic;
for (string::iterator i=word.begin();i!=word.end();++i,++pic)
*pic=*i;
*pic='\0'; //字符串结尾。
for(char *p=ic; *p!='\0';++p)
cout<<*p<<endl;
delete [] ic;
system("pause");
return 0;
}