2 回答
CurToken.append(&*Pointer);
Assuming Pointer
is a pointer, that's equivalent to
CurToken.append(Pointer);
and will append the entire tail of the string onto CurToken
(assuming it points to a C-style zero-terminated string; if there's no terminator then anything might happen). It looks like you just want to append the current character:
CurToken.append(*Pointer);
UPDATE: you say that Pointer
is std::string::iterator
. In that case, &*Pointer
is still a pointer to the character; and append
will still interpret it as a pointer to a C-style string. Since the characters in a string aren't necessarily terminated (although in practice they almost certainly will be, especially in a C++11 library), you've got undefined behaviour.
What are the types of CurToken
and Pointer
? CurToken
looks like a std::string
. Is Pointer
a std::string*
? append
has quite a few overloads. One of them is:
string& append ( const string& str );
If you want to hit that one you should get rid of the '&' to give you just the dereferenced pointer:
CurToken.append(*Pointer);
That should work, but remember that it'll append the whole string not just the character. If it doesn't you probably need to figure out which overload of append()
it's hitting. If you want the first character only, try:
CurToken.append(1, (*Pointer)[0]);