Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您好,我在 C++ 中修剪字符串时遇到问题。它在字符串的末尾添加了一些奇怪的字符。
string& Napis::subst(char cold, char cnew) { string * s = new string(data); replace(s->begin(),s->end(), cold, cnew); return *s; // takes back string s with changed sign }
我敢打赌你是subst在cnew设置为零的情况下跟注。您期望这会删除字符,但这不是它的作用。正如其名称所暗示的那样,它将它们替换为零。
subst
cnew
怎么样:
string Napis::subst(char cold, char cnew) { assert(cnew != 0); string s = data; replace(s.begin(), s.end(), cold, cnew); return s; // takes back string s with changed sign }