I’m trying to read an ifstream into a string, where I can set the number of characters being read. I’ve read the documentation for ifstream.get() and ifstream.getline(), but neither of those accomplish what I want.
Given the following string:
asdfghjklqwertyuiop
I want to read in varying number of characters at a time into a string. I’ve started like this, but I’m getting an error that there’s no function that will take a string as the first parameter:
string destination;
int numberOfLettersToGet = 1;
while (inputstream.get(destination, numberOfLettersToGet)){
//Do something.
}
What can I use instead of inputstream.get()?
You may like to use
readandgcountmember-functions ofstd::istream.getappends a zero-terminator, which is unnecessary when you read intostd::string.