2016-11-13 9 views
-1

C++の新機能で、現在ユーザーが設定できるリンクリストの中に電話番号と名前を挿入しようとしています。どこが間違っているのだろうと思っています。ビデオの後にビデオを見ていましたが、すべてがリンクリストではなく文字列ではなく整数で使用されています。C++リンクされたリストの文字列の問題

メインを取り出した場合、プログラムは(0)エラーと(0)警告を表示するので、問題はメインにあると思います。

私はmain(私はset_firstの関数部分の中にあるものです)をcinにしようとしています。私はそれに住所を渡そうとしましたが、私はちょうどそれでストローを引っ張っていると思います。

質問:誰かが私を正しい方向に向けることができますか、またはユーザーが指定するノードに名前と電話番号をどのように入れることができますか?

ここに私のプログラムは、これまでの主からの降順です:

#include <iostream> 
#include <cstdlib> 
#include "l_List_1.h" 

using namespace std; 

int main() 
{ 
    l_List_1 obr; 

    std::string nam; 
    cout << "name"; 
    cin >> nam; 
    obr.set_first(nam); //I'm trying to give it the nam since that's what I have inside my set_first function. 



return 0; 
} 

は私のヘッダファイルには、次のようになります。

#ifndef L_LIST_1_H 
#define L_LIST_1_H 


class l_List_1 
{ 
public: 
    l_List_1(); 
    void set_first(std::string nam, int phnum); 
    void delete_Node(std::string del_nams, int num_del); 
    void display(); 
    char menu(); 


private: 
    typedef struct node { 
     std::string user_Name; 
     int user_Phone; 
     node* next; 
    }* nodeptr; 

    nodeptr head; 
    nodeptr curr; 
    nodeptr tail; 
    nodeptr temp; 
}; 

#endif // L_LIST_1_H 

と私のcppファイルはここにある:

#include <iostream> 
#include <cstdlib> 
#include <string> 
#include "l_List_1.h" 

using namespace std; 


l_List_1::l_List_1() 
{ 
    head = NULL; 
    curr = NULL; 
    tail = NULL; 
} 

void l_List_1::set_first(std::string nam, int phnum) { 
    nodeptr n = new node; 
    n->next = NULL; 
    n->user_Name = nam; 
    n->user_Phone = phnum; 

    cout << "name"; 
    cin >> nam; 

    if (head != NULL) { 
     curr = head; 
     while (curr->next != NULL) { 
      curr = curr->next; 
     } 
     curr->next = n; 
} 
    else { 
     head = n; 
    } 
} 

void l_List_1::delete_Node(std::string del_nams, int num_del){ 
    nodeptr delptr = NULL; 
    temp = head; 
    curr = head; 
    while(curr != NULL && curr->user_Name != del_nams && curr->user_Phone != num_del){ 
     temp = curr; 
     curr = curr->next; 
    } 
    if(curr == NULL){ 
     cout << del_nams << "Was not in the list"; 
     cout << num_del << "was not in the list"; 
     delete delptr; 
    } else{ 
     delptr = curr; 
     curr = curr-> next; 
     temp->next = curr; 
     delete delptr; 
     cout << "the item" << del_nams << "was deleted"; 
     cout << "the item" << num_del << "was deleted"; 
    } 
} 

void l_List_1::display(){ 
    curr = head; 
    while(curr != NULL){ 
     cout << curr->user_Name; 
     cout << curr->user_Phone << endl; 
     curr = curr->next; 
    } 
} 
+1

あなたの質問には何かがありません。それは実際の質問でしょう。 –

答えて

0

のためにスターターメンバー関数set_firstは2つのパラメーターで宣言されています

void set_first(std::string nam, int phnum); 

あなたはリストの末尾を設定していない(とのノードを削除します。第二の機能で)関数自体では、1つの引数

obr.set_first(nam); 

でそれを呼び出しますが。

また、これらの記述は機能

cout << "name"; 
cin >> nam; 

にあなたがそれらを削除すべきである何をすべきか明確ではありません。

し、代わりにそれらのあなたはメソッド内のローカル変数を使用することができ、次のデータメンバー

nodeptr curr; 
nodeptr temp; 

を宣言しても意味がありません。

あなたは<string>

#include <string> 

ヘッダを含めるべきであると私は、ヘッダー<cstdlib>から何かがあなたのプログラムで使用されていることがわかりません考慮してください。ヘッダーを削除することができます。

+0

助けてくれてありがとう。 – Gus

+0

@Gusいいえ。:) –

関連する問題