Originally Posted by
DecoratorFawn82
(...)
Since the text book have only covered these string functions and
actually nothing about the keyword auto.
Yah ok, that's fair enough. So from what I understand, you:
1. Try to find the first letter of ord in text and store that location in pos.
2. Get a substring (ordet) from text with the length of ort, starting at pos.
3. Compare ordet to ort to see if they are actually the same word and don't just share the same first and last letter.
If that's what you want to do, then you can just use the == operator to compare those two strings, the same way you would e.g. compare two integers.
Note that you should generally use 64-bit unsigned integers to handle container positions. Using int could lead to unexpected behaviour later on.
Code:
size_t pos = text.find(ord.at(0)); // size_t can hold any value find() returns, int cannot
size_t ord_langd = ord.length();
As a matter of style, I would advise to initialize your variables directly if possible.
Code:
int ord_langd = ord.length();
string ordet = text.substr(pos, ord_langd); // we assign to ordet on declaration
You may also notice that ord_langd gets used immediately, so you could get rid of it unless it hurts clarity.
Code:
string ordet = text.substr(pos, ord.length());