Mac OS X 10.7.5上的编译器问题

时间:2012-10-09 03:08:58

标签: gcc osx-lion xcode4.5

我是使用C ++的新手,并且在很长一段时间内都无法解决此问题。 当我在正在使用的Xcode上运行时,代码给出了exc_bad_access(at some_list.size())错误 gcc版本4.2.1(LLVM build 2336.11.00)。但是,当使用g ++从命令行运行它时,我能够正常运行。

我在XCode上只有一个编译器选项,LLVM GCC 4.2,当我尝试运行代码时也会抛出相同的错误。

编辑: txt文件中的样本行看起来像“1'\ t'2,3'\ t'200,109'\ t'10,30'\ 0'”

    struct data {
        int head;
        int weight;
    };

    struct node {
        int vertex;
        list<data> edge;
    };



    void ReadGraphs(string path, list<node> & v) {
        char buff[1000];
        char* pch;
        node currNode;
        data currData;
        list<data> _edge;
        list<node> _v;
        int n = 0, m = 0;
        list<data>::iterator id; 

        ifstream myfile;
        myfile.open(path.c_str()); 

        cout << "Size of graph " << v.size() << "size of list " << _edge.size() << endl;

        if (myfile.is_open()) {
            cout << "File exists!" << endl; 

            while(!myfile.eof()) {
                myfile.getline(buff, 1000);
                pch = strtok(buff, ",\t\r");
                //if new vertex start a new node
                currNode.vertex = atoi(pch);

                pch = strtok(NULL, ",\t\r");
                while(pch != NULL) {
                    currData.head = atoi(pch);
                    n = max(n, atoi(pch));
                    pch = strtok(NULL, ",\t\r");
                    currData.weight = atoi(pch);
                    _edge.push_back(currData);
                    m++;
                    if(pch != NULL)
                        pch = strtok(NULL, ",\t\r");
                }
                cout << currNode.vertex << endl;

                currNode.edge = _edge;
                for(id = currNode.edge.begin(); id != currNode.edge.end(); id++) 
                    cout << id->head << "\t" << id->weight << endl;
                cout << "Size of graph " << v.size() << endl;
                v.push_back(currNode);
                currNode.edge.clear();
                _edge.clear();
                //cout << currVtx << "\t" << atoi(pch) << endl;
            }
        }


    }

0 个答案:

没有答案