c++中如何将输入的字符串(不知长度)存入数组中?

如题所述

第1个回答  推荐于2019-08-22
#include<iostream>
#include<string>
#include<windows.h>
using namespace std;
int main()
{
string str;
char temp;
cout<<"输入,按结束输入"<<endl;
while((temp=cin.get())!='\n')
{
str +=temp;
}
const int LEN =str.length();
char* dest = new char[LEN];//根据输入字符串的长度,创建字符数组
for(int i = 0;i<LEN;i++) //将字符串保存到字符数组中
{
dest[i]=str[i];
cout<<dest[i];
}
delete dest;
system("pause");
return 0;
}本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网