I am working on a project where we are taking latin words such as "amare" and replacing the end (are, ire, ere) with infinitives like ("o", "amus" etc)
For example if I input "amare" im supposed to cout the conjugate like: amo, amamus etc.
The problem I am running into is deciding whether a string has "are", "ire" or "ere" at the end. I have posted my code below. I have tried with if/else statements and while loops but I keep getting "exception abort code 6". I dont know if this is a correct way to do this. I should mention in prints "are" words but when I enter "ire" it fails.
The conditions of all the while loops invoking the std::basic_string<>::find() member function will always be true if the value returned by the aforementioned member function is not zero. When the given argument for std::basic_string<>::find() is not found within the string, std::basic_string::npos (-1) is returned. Therefore, your loops will continue iterating until the string being searched for is located at the start of infin.
Compare the result of std::basic_string<>::find() to std::string::npos using the inequality operator (!= or not equal to) in the conditions of the inner while loops to fix the problem.
The problem I am running into is deciding whether a string has "are", "ire" or "ere" at the end.
I suggest you use the std::basic_string<>::substr() member function.
I would use substr() but I unfortunately do not know how many characters will be in the input (our professor will be using random latin verbs). Could I use find(are, ire, ere)? and then compare the end of that string to see which one it is? Basically I'm unsure of how to determine whether or not the end of the string is are, ere, or ire. If you could help me out that would be great or I could get some tutoring tomorrow. The project isnt due until thursday, I just thought id take a crack at it now.
I would use substr() but I unfortunately do not know how many characters will be in the input (our professor will be using random latin verbs). Could I use find(are, ire, ere)? and then compare the end of that string to see which one it is? Basically I'm unsure of how to determine whether or not the end of the string is are, ere, or ire. If you could help me out that would be great or I could get some tutoring tomorrow.
An object of type std::string is aware of its size (how many characters it contains), so there is no need for you to know anything about the input given by your professor.
Using the std::string::substr member function and the std::string::size member function you can obtain the characters at the end of the string object and then compare them to are, ire, and ere.