#include <iostream>
#include <cctype>
#include <string>
using namespace std;
int main()
{
string text;
string numbers;
string characters;
string spaces;
getline(cin, text);
int i;
for (i=0; i<text.length(); i++)
{
if (isalpha(text[i]))
{
characters += text[i];
}
else if (isdigit(text[i]))
{
numbers +=text[i];
}
else
{
spaces +=text[i];
}
}
cout<<"Numbers in the string: "<<numbers<<endl
<<"Alphabets in the string: "<<characters<<endl
<<"Spaces in the string: "<<spaces.length()<<endl<<endl;
string searchstr;
string replacestr;
double n = text.length();
cout<<"Enter a word to search: "<<endl;
getline(cin, searchstr);
cout<<"Enter a replacement word: "<<endl;
getline (cin, replacestr);
double position = text.find(searchstr, 0);
text.replace (position, n, replacestr);
cout<<"Replaced string is: "<<endl
<<text<<endl<<endl;
return 0;
}
无法弄清楚这里发生了什么。它与正在使用的库有关吗?
Error:
Ld "/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Products/Debug/Project 4" normal x86_64
cd "/Users/andy/Desktop/EECS138/Project 4"
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Products/Debug -F/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Products/Debug -filelist "/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Intermediates/Project 4.build/Debug/Project 4.build/Objects-normal/x86_64/Project 4.LinkFileList" -mmacosx-version-min=10.8 -stdlib=libc++ -o "/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Products/Debug/Project 4"
duplicate symbol _main in:
/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Intermediates/Project 4.build/Debug/Project 4.build/Objects-normal/x86_64/main.o
/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Intermediates/Project 4.build/Debug/Project 4.build/Objects-normal/x86_64/File.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation
不知道为什么 Xcode 无法构建/运行程序,它在 CodeBlocks 中运行得非常好。关于为什么它给我这个错误的任何帮助?