Hello. I am currently trying to write code for finding unique lines as well as unique words. I have my attempted code below for unique lines but it is not calculating correctly when it comes to unique lines. I believe it is ignoring enters and still counting lines that contain letters, words, sentences, etc. So I need help in figuring out what to add that it will count enters as a line and not count any extra lines that are the same.
Example:
this is a test code
this test code has multiple lines
there are blank lines as well
this line is not the same
this line is not the same
Total unique lines: 5
My code is printing out 5 unique lines but it is not correctly counting the right lines. I know this too because I have tested other lines. As for the unique words, I don't even know how to get started :/
This should work, if I understand what it is you're trying to achieve.
You pass a line to the function as a string. The first time the function gets called, it instanciates a static std::set<std::string>, which means the container's life time is not constricted by the scope of the function.
Then, you insert the line to the set. If the same line already exists within the container, the size of the container will remain the same.