try catch throw
#include <iostream>
#include <fstream>
ofstream gaming;
gaming.open("games.txt");
gaming << "nintendo 1981 mario donkeykong \n";
gaming << "sega 1991 sonic tails \n";
gaming << "fun young sun happy \n";
gaming << "enjoy sweet hugs toys \n";
gaming.close();
cin.get();
how do I terminate it if the file doesnt exist
It would help if you posted a program rather than a code fragment.
@kbw, look at previous questions. They are senseless.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
template<class gamer>
class game
{
private:
protected:
int nintendo;
int sega;
string fun;
bool enjoy;
public:
};
template<class gamer>
class cookies : public game<gamer> {
public:
void vjello(string joy_in)
{
jello = joy_in;
}
string sjoy()
{
return jello;
}
cookies() {}
cookies(std::string description)
: description(description)
{ }
std::string description;
private:
string jello;
string joy;
};
int main()
{
ofstream gaming;
gaming.open("games.txt");
gaming << "nintendo 1981 mario donkeykong \n";
gaming << "sega 1991 sonic tails \n";
gaming << "fun young sun happy \n";
gaming << "enjoy sweet hugs toys \n";
gaming.close();
cin.get();
template<class gamer>
std::vector<cookies> vec(5);
template<class gamer>
vec[0] = cookies("Tasty");
template<class gamer>
vec[1] = cookies("Delicious");
template<class gamer>
vec[2] = cookies("Yummy");
template<class gamer>
vec[3] = cookies("Hungry");
template<class gamer>
vec[4] = cookies("Full");
return 0;
}
|
this is probably what you are looking for
1 2 3 4 5 6 7
|
if(!gaming.is_open()){
return 0; // error opening file
}
|
Last edited on
Topic archived. No new replies allowed.