I really can't understand why this code genereates a runtime error. The program actually outputs the text in the file and then the error occurs. Thankful for help.
Oh, the file deck.txt looks like this:
Code:
diabolic edict#
circle of protection#
nantuko vigilante#
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
void add(vector<string> &rDeck, char *card);
void readfile(vector<string> &rDeck);
int main()
{
vector<string> deck;
readfile(deck);
cout<<deck.at(0);
cout<<deck.at(1);
cout<<deck.at(2);
return 0;
}
void add(vector<string> &rDeck, char *card)
{
string s;
s.assign(card);
rDeck.push_back(s);
}
void readfile(vector<string> &rDeck)
{
char *card;
string s;
ifstream fin;
fin.open("deck.txt");
for(int i = 0;i < 3;i++)
{
fin.get(card, 40, '#');
fin.ignore();
add(rDeck, card);
}
fin.close();
}