To use getline, you aren't required to know the length of the input, you simply need to know the istream object, the variable, and (optionally) the character delimiter (what's used to stop getline).
Some examples:
1 2 3
std::string myString;
std::cin.getline(myString); // My preference
std::getline(std::cin, myString, '\n'); // Reads until a new line is reached
How do you determine the end of that variable length input? If it's up to the end of line or up to some sspecific delimiter, then it's std::getline (you don't have to tell it any length, it writes into a string, which expands as needed). If it's to the end of file, a convenient way is istreambuf_iterator<char>.