Someone told me that my programming methods are "weird" and not proper. I want some C++ veterans to look at my code and give me some pointers(not *).
Code:
#include <iostream>
#include <fstream.h>
#include <conio.c>
#include <string>
#include <windows.h>
class streaming
{
public:
void UserInfo();
void Fout();
void Fread();
streaming();
~streaming();
protected:
ofstream x;
ifstream y;
char filename[20];
string line;
string word;
string name;
unsigned short int age;
unsigned char response[20];
}io;
streaming::streaming()
{
line="";
word="";
}
streaming::~streaming()
{
}
void streaming::UserInfo()
{
cerr << "Input your character's name: ";
cin >> name;
cerr << "\nInput your character's age: ";
cin >> age;
io.Fout();
}
void streaming::Fout()
{
cerr << "\nInput the name of the file we will print out to: ";
cin >> filename;
char *file;
file=new char[20];
file=&filename[20];
x.open(file);
x << "Name: " << name << endl;
x << "Age: " << age << endl;
x.close();
delete [] file;
file=NULL;
}
void streaming::Fread()
{
char *file;
file=new char[20];
file=&filename[20];
cerr << "\nHow would you like us to read the file, line by line or word by word?";
cin >> response;
if (response[0]=='l' || response[0]=='L' || (response[0]=='l' && response[1]=='i' && response[2]=='n' && response[3]=='e') || (response[0]=='L' && response[1]=='i' && response[2]=='n' && response[3]=='e') ) {
y.open(file);
while (y.good() ) {
std::getline(y, line);
if (!y.eof()) {
cerr << line;
y.clear(); }
else {
y.close(); }
}
y.close();
}
else if (response[0]=='w' || response[0]=='W' || (response[0]=='w' && response[1]=='o' && response[2]=='r' && response[3]=='d') || (response[0]=='W' && response[1]=='o' && response[2]=='r' && response[3]=='d') ) {
y.open(file);
while (y >> word) {
if (!y.eof()) {
cerr << word << " ";
y.clear(); }
else {
y.close(); }
}
y.close();
}
else {
cerr << "\nCouldn't understand your input, bailing out of here!!" << endl;
cin.get(); }
delete [] file;
file=NULL;
}
int main()
{
streaming *x;
x=new streaming;
x->UserInfo();
Sleep(1000);
cerr << endl;
x->Fread();
delete x;
x=NULL;
getch();
return 0;
}