I was wondering if there is a way of using the cin.get() fuction in a loop to read a string that could be composed of more than one word.
For example
while (cin.get(chr)) // This gets stuck asking the user for input
while (cin.get(chr) && chr != '\n') // This code doesn't allow the '\n' to be read inside the loop
I want to be able to read a whole string and be able to use my chr variable to determine if the current character being read is a '\n' character.
I'm a little familiar with the getline function. But I don't know of a way to individually go through every character in the string while counting them when using the getline. I hope what I'm saying makes sense. I'm new to programming and c++.
I basically want to determine when these characters ( ' ' , '\n') happen in my string. I will use this to determine when a word ends and a new one begins in my string.
operator>>reads by default, iestring word; while (cin >> word) { ... }. Or, if you want to read words in a single line:string line, word; while (getline(cin, line)) { istringstream iss(line); while (iss >> word) { ... }}