在我的 C++ 代码中,我想写字符数组 s[n] 而不是写 s[10]。其中 n 是 size 是数组,它由用户在运行时给出。但它不接受输入。它只取 n,而不是字符串。
我得到了这样的输出,
输入尺寸:10
输入字符串:
细绳 :
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int n;
cout<<"Enter size : ";
cin>>n;
char s[n];
cout<<"Enter String : \n";
cin.getline(s,n);
cout<<"String : \n";
int l=strlen(s);
cout.write(s,l);
return 0;
}
Run Code Online (Sandbox Code Playgroud) c++ ×1