C ++到很多错误。怎么修?

时间:2016-01-31 21:51:49

标签: c++

我参加过C ++编程的初学者课程,并且非常喜欢它,以至于我一直在教自己第二课中的章节。到目前为止,材料不是复杂的函数,数组,向量。但是,我正在从书中解决一个问题,它要求我用两个不同的文本文件填充两个字符串向量,每个文本文件包含一个字符串列表 - 包括带空格的名称。我运行了我的代码,并在第一个工作正常。我使用相同的方法进行第二次文本拉取并出现了一些错误。

我从来没有碰到这样的事情,所以我不确定这意味着什么。我得到20个错误,它说它现在停止了。这不是让我编译任何其他程序。我该如何解决这个问题?

我已经在下面复制并粘贴了这个输出。也有人可以向我解释这一点,以了解有关这些错误的更多信息。

谢谢!

这是我第一次在这里发帖提问,对不起有困惑。 我对我提交的代码做了一些小修改。

我的问题:我的getTeam函数在输出从文本文件中提取的内容时正常工作。但后来我输出了getWinners向量,就在我看到这个错误发生的时候。另外需要注意的是第二个文件包含2个空行的团队获胜者列表,这是故意的。我添加了代码,我添加了下面的代码以及我在XCode中看到的错误。

#include <iostream>
#include <vector>
#include <fstream>
#include <string>

using namespace std;

const int teams=15;
const int  winning_teams=24;

void getTeams(vector<string> , const int);
void getWinners(vector<string>, const int);

int main()
{
    int count;
    vector<string> names;
    vector<string> winners;

    getTeams(names, teams);
    getWinners(winners, winning_teams);

    for(count=0; count<teams; count++)
        cout<<names[count]<<endl;
    return 0;
}
void getTeam(vector<string> names, teams)
{
    int count;
    ifstream inputFile;

    inputFile.open("/Users/Desktop/Teams.txt");

    for(count=0; count<teams; count++)
        getline(inputFile, names[count]);
    inputFile.close();
}
void getWinners(vector<string> winners, win_teams)
{
    int count;
    ifstream inputFile;

    inputFile.open("/Users/Desktop/WorldSeriesWinners.txt");

    for(count=0; count<winning_teams; count++)
        getline(inputFile, winners[count]);
    ifstream.close();
}


















CompileC /Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/Objects-normal/x86_64/main.o Ch7\ Continued\ Alone/main.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
    cd "/Users/franciscoavalosjr/Desktop/Class_Assignments/2nd class my study/Ch7 Continued Alone"
    export LANG=en_US.US-ASCII
    /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu++11 -stdlib=libc++ -fmodules -gmodules -fmodules-cache-path=/Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DDEBUG=1 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.11 -g -fvisibility-inlines-hidden -Wno-sign-conversion -iquote /Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/Ch7\ Continued\ Alone-generated-files.hmap -I/Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/Ch7\ Continued\ Alone-own-target-headers.hmap -I/Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/Ch7\ Continued\ Alone-all-target-headers.hmap -iquote /Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/Ch7\ Continued\ Alone-project-headers.hmap -I/Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Products/Debug/include -I/Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/DerivedSources/x86_64 -I/Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/DerivedSources -F/Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Products/Debug -MMD -MT dependencies -MF /Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/Objects-normal/x86_64/main.d --serialize-diagnostics /Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/Objects-normal/x86_64/main.dia -c /Users/franciscoavalosjr/Desktop/Class_Assignments/2nd\ class\ my\ study/Ch7\ Continued\ Alone/Ch7\ Continued\ Alone/main.cpp -o /Users/franciscoavalosjr/Library/Developer/Xcode/DerivedData/Ch7_Continued_Alone-bkufqcslkavkjzajreyppcxdsdgr/Build/Intermediates/Ch7\ Continued\ Alone.build/Debug/Ch7\ Continued\ Alone.build/Objects-normal/x86_64/main.o

In file included from /Users/franciscoavalosjr/Desktop/Class_Assignments/2nd class my study/Ch7 Continued Alone/Ch7 Continued Alone/main.cpp:9:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1674:1: error: expected member name or ';' after declaration specifiers
.
^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1393:26: error: use of undeclared identifier 'get_pointer'
        {return iterator(get_pointer());}
                         ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1396:32: error: use of undeclared identifier '__get_pointer'
        {return const_iterator(__get_pointer());}
                               ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1399:26: error: use of undeclared identifier '__get_pointer'
        {return iterator(__get_pointer() + size());}
                         ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1402:32: error: use of undeclared identifier '__get_pointer'
        {return const_iterator(__get_pointer() + size());}
                               ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1431:31: error: use of undeclared identifier '__get_long_size'
        {return __is_long() ? __get_long_size() : __get_short_size();}
                              ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1431:51: error: use of undeclared identifier '__get_short_size'
        {return __is_long() ? __get_long_size() : __get_short_size();}
                                                  ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1435:32: error: use of undeclared identifier '__get_long_cap'
        {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
                               ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1600:79: error: use of undeclared identifier '__get_pointer'
    const value_type* data() const _NOEXCEPT  {return _VSTD::__to_raw_pointer(__get_pointer());}
                                                                              ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1603:60: error: use of undeclared identifier '__alloc'
    allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
                                                           ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1776:18: error: use of undeclared identifier '__align_it'
                 __align_it<sizeof(value_type) < __alignment ?
                 ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1776:50: error: use of undeclared identifier '__alignment'
                 __align_it<sizeof(value_type) < __alignment ?
                                                 ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1817:17: error: use of undeclared identifier '__alloc'
            if (__alloc() != __str.__alloc())
                ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1822:13: error: use of undeclared identifier '__alloc'
            __alloc() = __str.__alloc();
            ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1850:13: error: use of undeclared identifier '__alloc'
            __alloc() = _VSTD::move(__c.__alloc());
            ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1934:5: error: use of undeclared identifier '__zero'
    __zero();
    ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1945:5: error: use of undeclared identifier '__zero'
    __zero();
    ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1958:15: error: use of undeclared identifier '__get_short_pointer'
        __p = __get_short_pointer();
              ^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1963:40: error: use of undeclared identifier '__alloc'
        __p = __alloc_traits::allocate(__alloc(), __cap+1);
                                       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

2 个答案:

答案 0 :(得分:3)

一般情况下,这种情况会发生很多。

有时,当您遇到错误时,编译器无法很好地了解下一个符号的含义。例如,你忘了';'然后下一个变量或语句没有意义。错误级联,你会得到这样的东西。

其他时候,你会拼错一个变量定义,并在引用它的所有地方都会出错。

不要担心这个数字。担心第一个错误。解决这个问题并一次继续进行。不要让问题的数量吓到你。

答案 1 :(得分:0)

感谢任何试图提供帮助的人! 我真的很感激!

我自己想出了问题:当数组从文件中提取字符串时,向量不会使用相同的逻辑。我原始代码中的设置输出此错误,因为我试图以这种方式获取向量。

举个例子:

从文件到矢量的原始输入:

for(count=0; count<teams; count++)
    getline(inputFile, names[count]);

将文件中的输入更新为vector:

while(getline(inputFile, name))
    Teams.push_back(name);

另一个值得注意的特性是,在函数中作为参数传递时,默认情况下将数组设置为引用。向量不具有此默认功能,因此需要在原型或函数语句中使用&ampersand&amp; -sign。

-Francisco