What is wrong with this code? input has always the length of 4 in my function test, no matter if my string is actually longer or shorter.
#include <iostream>
#include <string>
using namespace std;
void test(char arr[]){
string input;
input = arr[0];
for (int i=1; i<sizeof(arr)/sizeof(char); i++){input=input+arr[i];}
cout << input << endl;
cout << "length: " << input.length() << endl;
}
int main(){
string input;
cout << "String: " << endl;
getline(cin, input);
char arr[input.length()];
for(int i=0; i<input.length(); i++) {arr[i] = input[i];}
test(arr);
}