this isn't an arduino specific error what you're trying to do is declare and initialize the variable in one statement which is causing the problem. As you've figured it out already. Declaring the variable first
and initializing it another statement does the job for you
Hope this helps. PS, try posting the error that you get during build process next time :)
I think this needs more explanation. Basically why you cant declare and initialize at the same time in this case is because Serial.read is a synchronous request. Declaring an object requires acquiring the space for it, running any constructors and whatsoever, and doing while Serial.read() is an IO blocking operation. You could declare and initialize a String class variable given it was a string constant but not with anything like get_input or Serial.read
Further here's what I've found for you.
Apparently the String class has a copy constructor which means when declaring the variable you initialize at the same time it uses the copy constructor, and which requires ADDRESS to a valid string(know that you can use a constant because C++ deals with all strings as the address to their first char). In your case the constructor raised an error because you pointed it to an undefined(Serial.read() ).
String mystring=Serial.read(); //error, uses copy constructor
However this would work
String mystring="hey juliet!" ; //uses the copy contructor which takes address to a char
Doing the same thing in two different lines works for the same reasons, it uses a different constructor
String mystring; //uses empty string constructor - okay so far
mystring=Serial.read(); // uses the overloaded = operator --okay