我全新安装了Anaconda,并创建了如下环境:
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include <cassert>
using namespace std;
const string fileName = "Patient.csv";
template <class Type>
struct Node
{
Type info;
Node<Type> *next;
};
template <class Type>
class LinkedList
{
Node<Type> *head;
int length;
public:
LinkedList();
LinkedList(const LinkedList&); // required by the Rule of Three
//~LinkedList();
LinkedList& operator=(const LinkedList&); // required by the Rule of Three
void processVector(vector<Type>);
void insert(const Type&);
void remove(const Type&);
void print(std::ostream &);
void displayList();
// other functions as required
private:
/*Node<Type> *head;
int length;*/
};
class PatientType
{
public:
PatientType();
PatientType(string patientSSN, string patientFName, string patientLName, string patientEmail, string patientNumber);
string getPSSN();
string getPFName();
string getPLName();
string getPEmail();
string getPNumber();
void setPatient(string PSSN, string PFName, string PLName, string PEmail, string PNumber);
void loadList(vector<PatientType> &iList);
private:
// Node<PatientType>* head; eliminated
// private stuff that has no bearing on this example
string pSSN;
string pFName;
string pLName;
string pEmail;
string pNumber;
};
template <class Type>
LinkedList<Type>::LinkedList()
{
length = 0; //To keep track of the length to be O(1) otherwise it will be O(n) when we traverse throughout the whole linked list.
head = NULL; //The list is essentially empty
}
template <class Type>
void LinkedList<Type>::processVector(vector<Type> vecList)
{
Node<PatientType> *newNode = new Node < PatientType >;
int size = vecList.size();
for (int i = 0; i < size; i++)
{
newNode->info = vecList[i];
newNode->next = NULL;
if (head == NULL) //List empty
{
//newNode->info = vecList[i];
//newNode->next = NULL;
head = newNode;
cout << "I'm in the if statement (line 87)" << endl;
cout << "The head is: " << head->info.getPSSN() << endl;
}
else
{
cout << "I'm in the else statement (line 92)" << endl;
Node<PatientType> *temp = head;
while (temp->next != NULL)
{
temp = temp->next; //traverse the list
}
temp->next = newNode;
cout << "The head is: " << head->info.getPSSN() << endl;
}
length++;
cout << "Length is "<< length << endl;
}
}
template <class Type>
void LinkedList<Type>::displayList()
{
Node<PatientType> *temp;
temp = head;
while (temp != NULL)
{
cout << temp->info.getPSSN() << "\t" << temp->info.getPFName() << "\t" << temp->info.getPLName() << "\t" << temp->info.getPEmail() << "\t" << temp->info.getPNumber() << endl;
temp = temp->next;
}
cout << endl;
}
PatientType::PatientType()
{
/*pSSN = "SSN";
pFName = "First Name";
pLName = "Last Name";
pEmail = "Email";
pNumber = "Phone Number";*/
}
PatientType::PatientType(string patientSSN, string patientFName, string patientLName, string patientEmail, string patientNumber)
{
pSSN = patientSSN;
pFName = patientFName;
pLName = patientLName;
pEmail = patientEmail;
pNumber = patientNumber;
}
string PatientType::getPSSN()
{
return pSSN;
}
string PatientType::getPFName()
{
return pFName;
}
string PatientType::getPLName()
{
return pLName;
}
string PatientType::getPEmail()
{
return pEmail;
}
string PatientType::getPNumber()
{
return pNumber;
}
void loadPatientList(vector<PatientType> &iList)
{
ifstream infile;
string filePSSN;
string filePFName;
string filePLName;
string filePEmail;
string filePNumber;
infile.open(fileName);
while (!infile.eof())
{
getline(infile, filePSSN, ',');
getline(infile, filePFName, ',');
getline(infile, filePLName, ',');
getline(infile, filePEmail, ',');
getline(infile, filePNumber, '\n');
iList.push_back(PatientType(filePSSN, filePFName, filePLName, filePEmail, filePNumber));
}
infile.close();
}
int main()
{
ifstream file(fileName);
vector<PatientType> patientList;
loadPatientList(patientList);
LinkedList<PatientType> pList;
pList.processVector(patientList);
pList.displayList();
system("pause");
return 0;
}
我conda create --name etl
,然后是activate etl
。它安装了所有东西,但是当我去运行ipython时,我收到以下错误:
conda install ipython
在调查中,似乎anaconda在环境中创建了2个站点包:
请注意,此站点包位于环境的根目录。
此站点包不在根目录中,而是Traceback (most recent call last):
File "C:\Program Files\Anaconda3\envs\etl\Scripts\ipython-script.py", line 3, in <module>
import IPython
File "C:\Program Files\Anaconda3\envs\etl\lib\site-packages\IPython\__init__.py", line 54, in <module>
from .core.application import Application
File "C:\Program Files\Anaconda3\envs\etl\lib\site-packages\IPython\core\application.py", line 23, in <module>
from traitlets.config.application import Application, catch_config_error
File "C:\Program Files\Anaconda3\envs\etl\lib\site-packages\traitlets\config\__init__.py", line 6, in <module>
from .application import *
File "C:\Program Files\Anaconda3\envs\etl\lib\site-packages\traitlets\config\application.py", line 17, in <module>
from decorator import decorator
ImportError: No module named 'decorator'
的子目录,这是我所期望的。我想知道我做错了什么或者这可能是个错误吗?如果我手动将第一个site-directory中的文件移动到第二个,则错误就会消失。