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;
}
}
あなたの質問には何かがありません。それは実際の質問でしょう。 –