0

我正在尝试构建一个应用程序,该应用程序接受用户输入,将其放入向量/数据库并输出结果。当我将代码输入到我的 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;
}

主文件

#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

4

1 回答 1

1

构建程序发生在(至少)两个阶段,编译和链接。未定义的引用是链接器错误。如果您收到链接器错误,则表示编译成功。但是,如果您有编译器错误(例如,与分号有关的语法错误),则不会发生链接,因此您不会看到任何链接器错误(例如未定义的引用)。

于 2013-11-08T17:12:01.997 回答