can you help explain why the input validation doesn't work inside the createArr function, please? #include using namespace std; string* createArr(unsigned int arrSize); void displayArr(unsigned int arrSize); string* createArr(unsigned int arrSize) { string* newArr = new string[arrSize]; for(unsigned int i{0}; i < arrSize; i++) { string name{}; cout
@SnoopGod04202 жыл бұрын
Hello was wondering if there is a way to do this with characters, I am making a program in school that receives a random string and looks for the longest streaks of C so ADDDCCCCCBSIJCCCJJJJSKSKCCC Would get 5 being longest streak been stuck on for a while and cannot find anything online I understand enough to remember for exam practice
@astechigen61743 жыл бұрын
Would be nice if you introduce the definition of error flags before using it and explain why do we have to "reset" cin (or why it "messes up" in the first place). I've understood that when we assign an invalid value to a data type somewhat error occurs and we have to clear the buffer (I don't know what that does mean) to get rid of the error's consequences. But could you please get into the detail of this? Or at least explain it in simple terms.
@ferrabacus29803 жыл бұрын
Hey Rahmanyaz, the buffer is just temporary space like a file. So when the user enters in a response, it goes to a buffer, then gets pulled from the buffer to your program. That way we can easily direct it other places. The error flags are Boolean variables that are set to false when this event occurs, other parts of cin will check against those variables to see if it is still working properly so we have to reset them. I was trying to give an overview here instead of going into too much detail because it brings up a lot of conversations about classes, and those are generally learned much later! Hope this helps!