Originally Posted by
CodeMonkey
What do you need help with?
Since my last post I have updated the AI program. I need help specifically with seekg(). I need seekg() to retrieve data from the txt file back into the program. This stuff I posted before is fixed.
The program:
Code:
#include "stdafx.h"
class Index
{
fstream myFile;
HANDLE np;
unsigned threadID;
char selection;
string user;
public :
Index(void);
~Index(void);
int m(void); //menu
void r(void); //register
void l(void); //login
void un (void); //username
void pw (void); //password
void notepad(void);
static unsigned int __stdcall notepadThread(void* arg);
void AI (void);
void c(void); //clearscreen
void p(void); //pause
} index;
int Index::m(void)
{
c();
cout<<"Register = 1\nLogin = 2"<<endl;
cin>>selection;
switch (selection)
{
case '1' : { AI();
break;
}
case '2' : { AI();
break;
}
default : { cout<<"nope";
break;
}
}
return 1;
}
void Index::AI(void)
{
if (selection == 1 || 2)
{
c();
cout<<"Please Enter Your Username."<<endl<<"Username: ";
cin>>user;
un();
}
}
Index::~Index (void)
{
}
void Index::un(void)
{
while (myFile>>user);
{
myFile.open("record.txt", ios_base::app);
myFile<<"\n----------\n";
myFile<<&user;
myFile.close();
ifstream openfile("random.txt", ios::in);
if (openfile.is_open())
{
openfile.seekg(0);
openfile>>user;
cout<<user<<endl;
}
p();
if (! myFile)
{
cout<<"Error";
}
pw();
}
}
void Index::pw(void)
{
notepad();
}
Index::Index (void) {
np = 0;
}
unsigned int __stdcall Index::notepadThread(void* arg) {
system("notepad.exe record.txt");
_endthreadex(0);
arg = 0;
return 0;
}
void Index::notepad(void) {
np = (HANDLE)_beginthreadex( NULL, 0, &Index::notepadThread, np, 0, &threadID );
}
void Index::c(void)
{
system("CLS");
}
void Index::p(void)
{
system("pause");
}
int _tmain(int argc, _TCHAR* argv[])
{
Index index;
while(index.m());
return 0;
}
Here is what I currently need help with. The program isn't getting the addresses of the allocated strings I need.
Code:
void Index::un(void){
while (myFile>>user);
{
myFile.open("record.txt", ios_base::app);
myFile<<"\n----------\n";
myFile<<&user;
myFile.close();
ifstream openfile("random.txt", ios::in);
if (openfile.is_open())
{
openfile.seekg(0);
openfile>>user;
cout<<user<<endl;
}
p();
if (! myFile)
{
cout<<"Error";
}
pw();
}
}