我正在使用 Xcode,它在传递对字符串对象本身的引用时拒绝编译。
(string &text, string remove)
没有&
它编译。是我的代码错误还是项目文件有问题?
这是编译器错误:
Undefined symbols for architecture i386:
"removeLetters3(std::string, std::string)", referenced from:
Main() in narcissism.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
代码:
string removeLetters3(string &text, string remove)
{
for (int i = 0; i < remove.length(); i++)
{
int pos = 0;
while ((pos = text.find(remove[i], pos)) != string :: npos)
{
text.replace(pos, 1, "");
}
}
return "";
}
这是函数的调用方式:
string text;
string rletter;
removeLetters3(text, rletter);