As I take input from cin using the cin.get function, it will automatically update the read location from the input file. What should I do to return the read location to the beginning of the file, so that I can take in the input a second time?
Say for instance I have the following file input.txt:
"Say hello to your new world"
and the following get loop to take in the input.txt file:
while(cin.get(charTemp)){
numberOfChars++;
}
How could I take in the input twice?
You won't be able to reread the standard input stream. If you really need to read the content twice you'll have to store it, e.g.:
std::stringstream input;
input << std::cin.rdbuf();
input.seekg(0);
// use input and seek back to the beginning if needed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With