I'm trying to figure out how can I read the lines from a string of a user input.
I have a function outside of int main(). The way I want to do this is that for the first option, the code will read a text file and do the rest from there. I already got that cover. Now, I want to be able to allow the user to choose user input instead of fstream.
Somehow, the code below doesn't do anything. Not sure why but nothing is working. The code below will take the input string and count how many lines and words are there.
To make it more clear of what I'm doing. I have another exact piece of code as the one I provided.
Basically, I have two void functions that do the same. One is for ifstream and the other is for user input from the terminal. So, the problem is that the one for the user input is not working. I already managed to get the ifstream working.
and what coder is trying to tell you is that you have scrambled your variables a little. you read into input on line 4, and then try to use str which is still empty. Check each line and each variable and it should clear up. Which all credit goes to him; I am just repeating it...
Please type something and press ENTER (Q to exit): Hello word!
Please type something and press ENTER (Q to exit): I've nearly typed 2 rows...
Please type something and press ENTER (Q to exit): 1 last word
Please type something and press ENTER (Q to exit): goodby!
Please type something and press ENTER (Q to exit): Q
You've typed:
- 4 lines
- 11 words
- 54 characters
- 2 digits
Please, get into the habit of asking about compilable code.
For example, there must be a main() to compile it.
Please show your modified code and like already asked as compilable with main().
Basically, I have two void functions that do the same. One is for ifstream and the other is for user input from the terminal. So, the problem is that the one for the user input is not working. I already managed to get the ifstream working.
I don't see how that is possible.
We can only see what happening when you provide the code. Hopefully compilable.