2016-04-19 39 views
0
#include<iostream> 
#include<stdlib.h> 
#include<conio.h> 
#include <ctime> 
#include <fstream> 
#include <windows.h> 
#include <string> 
using namespace std; 


/* data variable is used to store data as name 
suggests,the "next" is a pointer of the type node 
that is used to point to the next node of the 
Linked List*/ 
/* 
* Node Declaration 
*/ 
struct node 
{ 
    string info; 
    struct node *next; 
}*start; 

/* 
* Class Declaration 
*/ 
class single_llist 
{ 
    public: 
    node* create_node(string); 
    void insert_begin(); 
    void insert_pos(); 
    void insert_last(); 
    void delete_pos(); 
    void sort(); 
    void search(); 
    void update(); 
    void reverse(); 
    void display(); 
    single_llist() 
    { 
     start = NULL; 
    } 
}; 

/* 
* Inserting element in beginning 
*/ 
void single_llist::insert_begin() 
{ 
    string value; 
    cout<<"Enter the value to be inserted: "; 
    cin>>value; 
    struct node *temp, *p; 
    temp = create_node(value); 
    if (start == NULL) 
    { 
    start = temp; 
    start->next = NULL;   
    } 
    else 
    { 
    p = start; 
    start = temp; 
    start->next = p; 
    } 
    cout<<"Element Inserted at beginning"<<endl; 
} 

我发展我与开发的C++ program.I试图进入特定的词为txt文件,并保存程序them.Therefore我处理string.The程序给出了这样的错误:undefined reference to single_llist::create_node(std::string)并告诉我这里有错误,temp = create_node(value);我仍在研究解决此问题需要做什么?定义字符串节点链表

+1

您是否定义了函数'create_node'? – NathanOliver

回答

0

感谢@NathanOliver我想我尝试了错误的方式,而没有创建节点first.For创建节点检查下面的代码片段。

/* 
* Creating Node 
*/ 
node *single_llist::create_node(string value) 
{ 
struct node *temp, *s; 
temp = new(struct node); 
if (temp == NULL) 
{ 
    cout<<"Memory not allocated "<<endl; 
    return 0; 
} 
else 
{ 
    temp->info = value; 
    temp->next = NULL;  
    return temp; 
} 
} 
+0

我不确定这是否应该成为问题的答案或附录。如果这是问题的更多信息,请使用问题下方的编辑链接,将此信息添加到问题中,然后删除此答案。如果这是一个答案,它需要更多的解释。 – user4581301

+0

是的,对我来说是一个答案。因为'未定义引用single_llist :: create_node(std :: string)'错误是由于没有create_node函数。并且我在创建节点时给出了一段代码,可能对其他朋友也有用。谢谢@ user4581301 –