配列を保持する構造体に渡される整数のファイルを開こうとしていますが、そうしようとすると、出力にゼロが追加され、プログラムにさらに追加すると、コアがダンプされます。 、だから私は私が間違っていることとそれを修正する方法がわかりません。
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <cstdlib>
using namespace std;
struct Hand
{
int handCards[52];
int totalCards;
};
struct Card
{
char rank;
char suit;
};
void OpenFile (ifstream&, string&);
void ReadFile (ifstream&, Hand&);
void ProcessRank (Hand&, int CardRank[]);
void ProcessSuit (Hand&, int CardSuit[]);
char GetRank (int);
char GetSuit (int);
void PrintCard (Card);
Card ConvertRaw (Hand);
void PrintHand (Card, Hand);
int main()
{
ifstream inf;
string filename;
Hand theHand;
Card aCard;
int CardRank[13];
int CardSuit[4];
OpenFile(inf, filename);
ReadFile(inf, theHand);
}
void OpenFile (ifstream &inf, string &filename)
{
cout<<"What is the name of the file?" <<endl;
cin>>filename;
inf.open(filename.c_str());
if (inf.fail())
{
cout<<"Sorry, that file doesn't exist" <<endl;
exit(1);
}
else
cout<<"Success!" <<endl <<endl;
}
void ReadFile (ifstream &inf, Hand &theHand)
{
theHand.totalCards=0;
int i=0;
while(inf.good())
{
inf>>theHand.handCards[i];
theHand.totalCards++;
cout<<theHand.handCards[i];
i++;
}
}
ファイルは123456ですが、出力として1234560>を取得し、残りのコードを追加するとコアダンプが発生します。それが問題の通過なのか、それとも私の変数がどういうわけかオフになっているのかはわかりませんが、誰かが私を助けてくれるなら、それは大きな意味があります。