That has issues with precedence with surrounding <<s. Put the whole ternary thing in brackets.
(1) Deal with "times" or "time", i.e. if <= 1, then choose "time", and else choose "times". I tried conditional operator, (a>b)? c : d..., but somehow it gives errors all the time
Doesn't seem to do so.
(2) Does this program meet the requirements of the exercise (see the verbatim description of the exercise at the top of the program)
Write a function that reads words from an input stream and stores them in a vector. - Your function does much more than that.
Use that function BOTH to write programs that count the number of words in the input and to count how many times each word occurs - This seems to indicate that you write two programs?
std::cin is a global instance of istream. What you are expected to write is a function that might look like this:
(3) I don't understand much about istream& thing that the textbook uses to read words... Why is it used instead of the usual cin>>sth?
which can be used to read from std::cin, a file or a stringstream
std::vector<std::string> read_words(std::istream& is);
std::vector<std::string> from_console = read_words(std::cin);
std::vector<std::string> from_file = read_words(fin);
std::string s("one two three");
std::vector<std::string> from_string = read_words(ss);
You can't initialize a vector after it's been already created. You could only initialize it in the constructor of the struct you have.
(4) How can I initialize a vector? I've read and tried all possiblities: vector<int> vec(10, 1) for 10 elements, each = 1. But it doesn't work here somehow. Error warnings immediately. In this program, I've tried
wp.count(wp.v.size(), 1) to inititiaze every element of the vector count to 1. Errors always!
But you can resize it:
Do you like the output if words occur more than once?
(5) Lastly, if possible, please give me a hint/suggestions on how to improve this program.