I'm trying to create a bit of code that can read information from a file, and based off this information, create a number of objects. However... I want every object created to be called U001 where 001 increments each time an object is created.
How do I go about this?
for reference, here's the code I already have:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Unit
{
public:
int HP;
int Xcord;
int Ycord;
char ident[8];
char house[8];
char weap1[8];
char weap2[8];
char dispnam[32];
};
int main ()
{
cout << "Available sides:\n* ASIDE -- Side #A\n* BSIDE -- Side #B\n* CSIDE -- Side #C\n\n";
// Defining Variables used, creating an fstream object called Fileop
char LineT[256];
int LineN; LineN = 0;
fstream Fileop;
// Opening file Units.dat for input & Output
Fileop.open ("Units.dat",ios::in);
// Read and display file, 1 line at a time
while (!Fileop.eof ( ) ) {
Fileop.getline (LineT,256);
cout << LineT; cout << "\n";
if (strncmp (LineT,"-",1) == 0) {
Unit U001;
U001.HP = 400;
};
LineN = LineN + 1;
};
// Close the opened file
Fileop.close();
cin.get();
return 0;
}
All help is appreciated!