Get unformatted input with variable length

fpiro07 (29)
Is there any way to get unformatted input with variable length?

I know there's getline() but in order to use it you have to tell it the length of the stream and I don't have it.
Marcos Modenesi (27)
why don´t you use "string"?
(I´m new user, don´t take me far too serious)
Volatile Pulse (1329)
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 
Cubbi (1570)
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>.
fpiro07 (29)
Ok thank you very much guys you helped me a lot.
Registered users can post here. Sign in or register to post.