所以,.csv
我从一个文件创建用户,它来自 User 类。我正在尝试创建一个链接列表,它将包含所有用户,但是我将它们插入到链接列表中时出错,顺便说一下,它被命名为“ListaLigada”。我无法自己弄清楚。
所以,这就是我得到的:
错误 1 错误 LNK2019:函数“void __cdecl genUserLList(class ListaLigada &)" (?genUserLList@@YAXAAV?$ListaLigada@VUser@@@@@Z) C:\Users\Daniel\documents\visual studio 2010\Projects\Radio Station\Radio Station\Auxf.obj Radio Station
如果您能确定我做错了什么,我将不胜感激,到目前为止已经有 2 天了。
这是相关的代码:
ListaLigada.h
#pragma once
#ifndef ListaLigada_H
#define ListaLigada_H
#include <cstddef>
#include <cassert>
template<class T>
class ListaLigada
{
public:
ListaLigada();
ListaLigada(T elem);
~ListaLigada(void);
void insert(T elem);
void remElem(T elem);
void remElem(int id_elem);
void searchElem(int id_elem);
void searchElem(T elem);
void clear();
private:
struct Node{
T data;
Node *next;
Node *prev;
} *p;
size_t list_size;
};
#endif
ListaLigada.cpp
#include "ListaLigada.h"
template<class T>
ListaLigada<T>::ListaLigada()
{
list_size=0;
this->p=new Node;
this->p=NULL;
}
template<class T>
ListaLigada<T>::~ListaLigada(void)
{
clear();
}
template<class T>
ListaLigada<T>::ListaLigada(T elem)
{
node *q, *t;
if(p == NULL)
{
p=new Node;
p->data= elem;
p->next= Null;
list_size++;
}
else
{
q=p;
while(q->next!= NULL)
q= q->next;
t= new node;
t->data= elem;
t->next=Null;
t->prev=q;
q->next=t;
list_size++;
}
}
template <class T>
void ListaLigada<T>::insert(T elem)
{
node *q, *t;
if(p == NULL)
{
p=new Node;
p->data= elem;
p->next= NULL;
list_size++;
}
else
{
q=p;
while(q->next!= NULL)
q= q->next;
t= new node;
t->data= elem;
t->next=NULL;
t->prev=q;
q->next=t;
list_size++;
}
}
template <class T>
void ListaLigada<T>::remElem(T elem)
{
node *q, *t;
if(p== NULL)
{
system("cls");
cout<<"There's nothing to remove\n";
_getch();
}
else
{
q=p;
while(q->next != NULL){
//e se for o unico elemento?
if(list_size==1)
{
~ListaLigada();
//blahblah limpar ficheiros
break;
}
else
{
if(q->data.getId() == )
}
}
}
}
template <class T>
void ListaLigada<T>::remElem(int id_elem){}
template <class T>
void ListaLigada<T>::searchElem(int id_elem){}
template <class T>
void ListaLigada<T>::searchElem(T elem){}
// deletes all the list elements
template <class T>
void ListaLigada<T>::clear()
{
node *q;
if( p == NULL )
return;
while( p != NULL )
{
q = p->next;
delete p;
p = q;
listSize--;
}
//assert(listSize==0);
}
辅助文件
#ifndef AUX_H
#define AUX_H
//#include "includes.h"
#include "ListaLigada.h"
#include "Music.h"
#include "User.h"
#include "RadioStation.h"
#include <conio.h>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <list>
#define MIN_LEN 2
bool strMinLen(string str, int min_len);
void fillField(string &to_fill, const string &what_is);
void checkFiles();
void loadInfo(vector<int> &vec); //carrega ids maximos
void regUser();
void addMusic();
void updateRestoreTxt(const int &line);
void loadRestore();
void updateRestore();
//void genUserLList(list<User> &lista);
void genUserLList(ListaLigada<User>);
#endif
auxf.cpp //我将只发布相关的功能
void genUserLList(ListaLigada<User> &lista){
ifstream ifs;
ifs.open("users.csv");
if(ifs){
int to_read;
to_read=getNUsers(); //nr of users to read
string user_line;
getline(ifs, user_line, ','); //linha cabecalho
for(int i=0; i<to_read; i++){
user_line.clear();
string name, password;
int age;
char gender;
unsigned int id=0;
getline(ifs, user_line);
stringstream sstream;
sstream<<user_line;
string tmp;
stringstream sstmp;
char delim= ',';
getline(sstream, tmp, delim);
sstmp<<tmp;
sstmp>>id;
sstmp.clear();
tmp.clear();
getline(sstream, name, ',');
getline(sstream, tmp, ',');
sstmp<<tmp;
sstmp>>age;
sstmp.clear();
tmp.clear();
getline(sstream, tmp, ',');
sstmp<<tmp;
sstmp>>gender;
sstmp.clear();
tmp.clear();
getline(sstream, password, ',');
User n_user(id, name, age, gender, password);
/*list<User>::iterator it;
it=lista.end();
*/
lista.insert(n_user);
}
}
else{
cout<<"Lista Ligada ta fdd\n";
_getch();
}
}
提前致谢。我不知道该怎么办了...我正在阅读用户