I have Const variable :
#define ERROR_ME std::string("Error Message")
in the function, I want return std::vector so, I write this:
return std::vector<byte>(ERROR_ME.begin(), ERROR_ME.end()); // this have error
can you help me?
No you don't have a "Const [sic] variable", you have a symbolic constant that is replaced in the source before the compiler proper gets a chance to read it.
The code the compiler will see is not
return std::vector<byte>(ERROR_ME.begin(), ERROR_ME.end());
but instead
return std::vector<byte>(std::string("Error Message").begin(), std::string("Error Message").end());
That is, you get the begin and end iterators from two different and unrelated objects. Comparing or other interacting of unrelated iterators leads to undefined behavior.
If you want a true constant then use e.g.
std::string const ERROR_ME = "Error Message";
#defineto declare constants. If you want a constant useconst datatype = something;.