声明一个固定大小的字符串,然后输入

#include<bits/stdc++.h>
using namespace std;
int main(){
    int length;
    cin>>length;
    string s(length,'\0');
    cin>>s;
    cout<<s;
}

int the code above firstly im taking a int length and then using it to define the size of the string but the issue is that when i cin>>s after defining length the string still takes more char's than length i.e OUTPUT->

3
Hello
Hello

在定义了字符串的长度之后,就不会发生这种情况,