2013-04-22 3 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

+0

Вы можете выслать полную ошибку – Pradheep

+0

'Не вопрос Xcode. – 2013-04-22 18:41:56

ответ

0

Из вашей ошибки, похоже, что у вас есть файл main и еще один файл File, который обе определяют функцию main().

main() является точкой входа для вашей программы. Вы не можете определить две разные функции для вашей программы.

+0

Глупый меня. Вот и все. благодаря – iamthewalrus

Смежные вопросы