Answer the question
In order to leave comments, you need to log in
How to enter an indefinite number of lines in C++?
Hello. I’ll make a reservation right away, I just started studying strings, I don’t know vectors and much more ... You need to enter an indefinite number of strings. The problem is that I don't know how to do it. My knowledge is clearly not enough for this. Please, help.
Answer the question
In order to leave comments, you need to log in
Such a condition means that you need to work with the string character by character, and not write it all into memory, because there may not be enough memory.
Write the problem in full, because it is not clear what you need, but as an option to solve such tasks through a buffer. Conventionally, you copy a 50GB file, but instead of reading 50GB into memory, you read 1MB and remember the position until the copy is over.
If this is an arbitrary length in the sense of not "you need to count exactly 5 characters", then you can read in std::string. It will allocate enough memory on its own.
This is how one word is read until a space (or end of file):
std::string s;
std::cin >> s;
std::getline(cin, s);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question