2013-04-22 87 views
-1
#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; 
} 

無法弄清楚這裏發生了什麼。這是否與正在使用的圖書館有關?Apple Mach O Linker錯誤?

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中工作得非常好。任何幫助,爲什麼它給了我這個錯誤?

+1

什麼是錯誤? – bmargulies 2013-04-22 18:39:45

+0

你能發佈完整的錯誤 – Pradheep 2013-04-22 18:39:47

+0

'這不是一個Xcode的問題。 – 2013-04-22 18:41:56

回答

0

從你的錯誤,看起來你有一個文件main和另一個文件File都定義了main()函數。

main()是您程序的入口點。您無法爲您的程序定義兩種不同的功能。

+0

傻我。就是這樣。謝謝 – iamthewalrus 2013-04-22 18:44:41