Hello Mykel,
@ne555 Thanks for the tips. I liked the front and back.
To start I added these header files:
1 2 3
|
#include <cctype>
#include <chrono>
#include <thread>
| |
The last are used here:
1 2 3 4 5 6
|
if (fv.fail()) // <--- Could also be written as (!fv)
{
std::cout << "File can not be found";
std::this_thread::sleep_for(std::chrono::seconds(3)); // Requires header files "chrono" and "thread"
exit(1); // <--- Because there is no reason to continue.
}
| |
This way there is a pause to allow the user to read the message before the program ends and the console window closes.
To give you an idea I created a function.
I start with defining two variables "std::string word;" and "std::size_t len{};"
This way I take an element of the vector and put it into "word" to work with.
For "len" I set this to "word.size() - 1" to have the last element of the string
and as ne555 suggested to test if it is worth continuing or moving to the next
word.
While working on the function I realized that you will need to change the word
to either lower or upper case. Otherwise a comparison between different cases
would not work.
After this I check for punctuation and removed anything at the end. At this
point you could check the string for anything else you do not want like numbers
or spaces and remove them if needed.
If "word.front() == word.back()" I put this in the second vector for later
processing.
There are two functions that you will need to write. One to check each word and one to change to a single case.
Work something up and we can go from there.
Hope that helps,
Andy