我正在尝试构建一个应用程序,它接受用户输入,将其放入向量/数据库,然后输出结果。当我将代码输入到我的Windows命令提示符编译器时,它只是得到它给我一个路径C:/ users / app / data / local / temp然后一个未定义的引用错误几乎所有的东西,cin,cout等。它最初只是给我通常的错误,但当我删除它给我这个错误,而如果我要删除一个分号,它会给我一个错误。关于可能导致这种情况的任何想法?
MP3.H
#define MP3_H
#include <iostream>
#include<string>
using namespace std;
class MP3
{
public:
MP3();//constructor
MP3(string,string,int,int,string);
~MP3();
string getName() const;
string getSongName() const;
int getDuration() const;
int getReleaseYear() const;
string getReview() const;
private:
string artistMP;
string songMP;
int duationMP;
int releaseyearMP;
string reviewMP;
}
#endif
MP3.cpp
#include "MP3.h"
MP3::MP3();
MP3::MP3(string artist,string song,int duration,int releaseyear,string review){
artistMP=artist;
songMP=song;
durationMP=duration;
releaseyearMP=releaseyear;
reviewMP=review;
}
~MP3::MP3();
string MP3::getName()const;{
return artistMP;
}
string MP3::getSongName()const;{
return songMP;
}
int MP3::getDuration()const;{
return durationMP;
}
int MP3::getReleaseYear()const;{
return releaseyearMP;
}
string MP3::getReview()const;{
return reviewMP;
}
的main.cpp
#include<vector>
#include "MP3.h"
void fillVector(vector<MP3>&);//5
void print (const vector<MP3>&);//7
int main( )
{
vector<MP3> myRecord;
fillVector(myRecord);
print(myRecord);
return 0;
}
void fillVector(vector<MP3> & newMyRecord){//22
cout<<"How many songs in the playlist baby";
int recordSize;
cin>>recordSize;
for(int i=0;i<recordSize;i++)
{
string artist;
string song;
int duration;
int releaseyear;
string review;
cout<<"Enter Artist Name:";
cin>>artist;
cout<<"Enter Song Name:";
cin>>song;
cout<<"Enter Song Duration(in seconds):";
cin>>duration;
cout<<"Enter Release Year:";
cin>>releaseyear;
cout<<"Enter Brief Review:";
cin:review;
MP3 newMP3(artist,song,duration,releaseyear,review);
newMyRecord.push_back(newMP3);
cout<<endl;
}
cout<<endl;
}
void print (const vector<MP3>&newMyRecord)//58
{
unsigned int size = newMyRecord.size();
for (unsigned int i=0;i<size;i++){
cout<<"Artist:"<< newMyRecord[i].getName()<<endl;
cout<<"SongName:"<< newMyRecord[i].getSongName()<<endl;
cout<<"Duration:"<< newMyRecord[i].getDuration()<<endl;
cout<<"ReleaseYear:"<< newMyRecord[i].getReleaseYear()<<endl;
cout<<"Review:"<< newMyRecord[i].getReview()<<endl;
}
}
};
TIA
答案 0 :(得分:1)
构建程序发生在(至少)两个阶段,即编译和链接。未定义的引用是链接器错误。如果您收到链接器错误,则表示编译成功。但是,如果您有编译器错误(例如,使用分号的错误语法),则不会发生链接,因此您不会看到任何链接器错误(如未定义的引用)。