I am in the works of trying to write a program that reads in individual characters and prompts the user when the two-character-sequence 'cs' that the door has opened. I'm stuck on where or how to store the current value and output the response after the string has completely been read.
Data reading in from notepad:
cs
imacsmajor
css
ab
decds
Desired output:
cs open door
imacsmajor open door
css open door
ab closed door
decds closed door
code written so far:
//file: opendoor.cpp
#include <conio.h>
#include <fstream>// requires for external file streams
#include <iostream>
using namespace std;
// Associating program identifiers with external file names
#define in_file "data.txt"
#define out_file "resline.txt"
void main()
{
const char nwln = '\n'; // print a new line
ifstream ins; // associates ins as an input stream ofstream outs;
ofstream outs; // associates outs as an output stream
int door = 0;
char current, previous = ' ', password;
ins.open(in_file);
outs.open(out_file);
// Repeat processing until end of file is reached
ins.get(current);
while (!ins.eof())
{
cout << current ;
// read a character
while (current != '\n')
{
ins.get(current);
cout << current ;
}
}
_getch();
ins.close(); // closing input file
outs.close(); // closing output file
} // end main