无需构建:面向C++的Eclipse问题

Nothing to build: Eclipse Issues for C++

本文关键字:Eclipse 问题 C++ 面向 构建      更新时间:2023-10-16

我对Java和Eclipse有一些经验,但我是C++的新手,正在努力自学。如果这是一个简单的问题,或者已经被问到了(尽管我环顾四周了一段时间),我很抱歉。我使用的是Windows 8。

我正在尝试制作一个排序的链表(这相对不重要。)我得到了:

Info: Nothing to build for Working.

这是我的代码:

/*
*  SortedList class
*/
#include <string>
#include <fstream>
#include<iostream>
#include "SortedList.h"
using namespace std;
//the ListNode Structure
struct ListNode {
    string data;
    ListNode *next;
};
//the head of the linked list and the pointer nodes
ListNode head;
ListNode *prev, *current;
// insert a string into the list in alphabetical order
//now adds a string to the list and counts the size of the list
int Insert(string s){
//make the new node
ListNode temp;
temp.data = s;
//the node to traverse the list
prev = &head;
current = head.next;
int c = 0;
//traverse the list, then insert the string
while(current != NULL){
    prev = current;
    current = current->next;
    c++;
}
//insert temp into the list
temp.next = prev->next;
prev->next = &temp;
return c;
}
//Return the number of times a given string occurs in the list.
int Lookup(string s){
return 0;
}
//prints the elements of the list to ostream
void Print(ostream &output){
}
int main( int argc, char ** argv ) {
cout << Insert("a") << endl;
cout << Insert("b") << endl;
cout << Insert("d") << endl;
}

这是我的标题:

using namespace std;
#ifndef SORTEDLIST_H_
#define SORTEDLIST_H_
class SortedList {
  public:
    // constructor
    SortedList();
    // modifiers
    int Insert(string s);
    // other operations
    int Lookup(string s) const;
    void Print(ostream &output) const;
  private:
    struct ListNode {
       string data;
       ListNode *next;
    };
    // pointer to the first node of the list
    ListNode head;
    ListNode *prev, *current;
};
#endif /* SORTEDLIST_H_ */

如有任何帮助,我们将不胜感激。

为什么不使用std::deque(在头deque中)?它可能拥有你想要的所有功能,经过充分测试和优化。如果您需要一个具有更多功能的deque,请创建一个从中继承的类,并添加所需的函数。看看http://en.cppreference.com/w/cpp/containe并挑选最适合您需求的容器。

一般来说,如果你需要的东西已经在一些好的、稳定的库(STL、boost、GSL、Armadillo或类似的库)中可用,那么最好使用它,而不是自己从头开始编写+调试+优化它。作为一般建议,将精力集中在应用程序特有的代码上,并重用已经完成的代码(但只有在测试良好的情况下,不要使用糟糕的半熟库)。