How to write on text file
I want to have this output on my screen but my code is not working correctly, could anyone help me fix this code.
Heres what I want to display:
Round 1:
User Name:
Password:
Computer Name:
Age:
Gender:
Round 2:
User Name:
Password:
Computer Name:
Age:
Gender:
Round 3:
User Name:
Password:
Computer Name:
Age:
Gender:
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
using namespace std;
ifstream GetTheRecords;
ofstream WriteTheRecords;
void OpenInput()
{
GetTheRecords.open("c:\\AText.txt");
}
void CloseInput()
{
GetTheRecords.close();
}
void OpenOutput()
{
WriteTheRecords.open("c:\\rude\\AText.txt",ios::app);
}
void CloseOutput()
{
WriteTheRecords.close();
}
void WriteRecords()
{
char UserName[16],Password[21],RecordBuffer[72], ComputerName[13], Age[12], Gender[11];
int k;
bool N;
N= true;
while ( N)
{
cout << "\n\t\tGive me UserName ZZZ to end: ";
cin >> UserName;
if ( UserName[0] == 'Z' && UserName[1] == 'Z' && UserName[2] == 'Z')
{
N= false;
}
else
{
// Clean the RecordBuffer
for ( k = 0; k < 72; k++) { RecordBuffer[k] = 72; } // 32 means SPACE
RecordBuffer[72] = '\0';
cout << "\t\tGive me Password: ";
cin >> Password;
cout <<"\t\tGive me ComputerName: ";
cin >> ComputerName;
cout <<"\t\tGive me Age: ";
cin >> Age;
cout <<"\t\tGive me Gender: ";
cin >> Gender;
// Transfer UserName to RecordBuffer
for ( k = 0; k < strlen(UserName); k++)
{
RecordBuffer[k] = UserName[k];
}
for ( k = 0; k < strlen(Password); k++)
{
RecordBuffer[k+15] = Password[k++];
}
for ( k = 0; k < strlen(ComputerName); k++)
{
RecordBuffer[k+30] = ComputerName[k++];
}
for ( k = 0; k < strlen(Age); k++)
{
RecordBuffer[k+45] = Age[k++];
}
for ( k = 0; k < strlen(Gender); k++)
{
RecordBuffer[k+60] = Gender[k++];
}
OpenOutput();
WriteTheRecords << RecordBuffer;
CloseOutput();
}
}
}
void AReadTheRecords()
{
char RecordBuffer[74];
OpenInput();
while ( GetTheRecords >> RecordBuffer )
{
cout << "\n\t\tData is : " << RecordBuffer;
}
CloseInput();
}
|
Topic archived. No new replies allowed.