こんにちは、私は学校のプロジェクトに取り組んでおり、特定の機能で苦労しています。私はしばらくの間それに取り組んできました。どんな種類の情報もいただければ幸いです。
この関数を使用する必要があります。
bool movieLibrary::readMovieInfo(ifstream& inFile)
{
inFile>>rank>>year>>votes>>nationality;
getline(inFile,nameMovie);
if (rank < 1)
return false;
else
return true;
}
私のメイン関数は間違った出力を出し続けます:
#include "movieLibrary.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
movieLibrary myMovie[5];
ifstream inFile("myMovieLibrary.txt");
int i =0;
//my issue is here
while (myMovie[i].readMovieInfo(inFile))
{
i++;
myMovie[i].readMovieInfo(inFile);
}
for (int i=0;i<5;++i)
{
myMovie[i].printMovieInfo("printList.txt");
}
return 0;
}
ここに入力と同じはずの出力がありますが、ここに私が得ているものがあります:
3 2000 24446 b Snatch
2 2008 1902 b RocknRolla
5 2007 25510 a American Gangster
-1 -858993460 -858993460 Ì
-858993460 -858993460 -858993460 Ì
入力は次のとおりです: myMovieLibrary.txt
3 2000 24446 b Snatch
2 2004 2872 b Layer Cake
2 2008 1902 b RocknRolla
4 1999 7661 b Lock,Stock and Two Smoking Barrels
5 2007 25510 a American Gangster
-1
rank year votes Nationality (b:british; a:american) name
MovieLibrary 仕様ファイルは次のとおりです。
#include <string>
class movieLibrary
{
public:
movieLibrary();
~movieLibrary();
//void readMovieInfo(std::ifstream&);
bool readMovieInfo(std::ifstream&);
void printMovieInfo(char*);
char getNationality();
int getRank();
bool operator>=(movieLibrary) const;
bool operator<(movieLibrary) const;
private:
int rank; //rank I gave to the movie in my library
int year; //year the movie came out
int votes; //the number of votes that yahoo users gave the movie
std::string nameMovie; //the name of the movie
char nationality; //nationality of movie: b for british and a for american
};
MovieLibrary の実装クラス:
#include "movieLibrary.h"
#include <fstream>
#include <string>
using namespace std; // here you can use that.
movieLibrary::movieLibrary()
{
}
movieLibrary::~movieLibrary()
{
}
bool movieLibrary::readMovieInfo(ifstream& inFile)
{
inFile>>rank>>year>>votes>>nationality;
getline(inFile,nameMovie);
if (rank < 1)
return false;
else
return true;
}
void movieLibrary::printMovieInfo(char* outFileName)
{
std::ofstream outFile;
if(!outFile.is_open())
outFile.open(outFileName, std::ios::app);
outFile<<rank<<" "<<year<<" "<<votes<<" "<<nationality<<" "<<nameMovie<<std::endl;
}
int movieLibrary::getRank()
{
return rank;
}
char movieLibrary::getNationality()
{
return nationality;
}