0

I'm trying to take a program that takes in various of output from the program console and wanted to be able to process it later on. Also I have tried researching this myself but most keep the buffer on making it impossible to print after. It also doesn't matter if you have to print to a file either. I also want to read the files like the output, Line by line.

using namespace std;

sbuffer;//This would be the code to capture the c++ console output

cout << "This is a test sentence" << endl;
cout << "Second sentence" << endl;
cout << "Third" << endl;

sbuffer.close() //close the buffer

read = sbuffer 
for(int i = 0; i < read.length(); i ++){
   print(read[i]) // prints out each line. 

}
  • 1
    Sorry that I am not able to understand your english... Do you want to read the output from an other program into your own program to process these output later? Or do you want to process all the output from a shell with user interaction in between? – Klaus Sep 29 '19 at 07:54
  • I need to read the console output from the same program. I am doing this all from clion if that helps you understand what I am trying to achieve. – Kai Sato Sep 29 '19 at 08:36
  • What is "the same" program? The program which generates the output should read its own output or should your program read the output of ANOTHER program? BTW: if you answer to an comment, you should add @ so that the originator of the comment get a notification – Klaus Sep 29 '19 at 08:38
  • "The program which generates the output should read its own output" <-- This. @Klaus – Kai Sato Sep 29 '19 at 09:16

1 Answers1

0

Just use Files and Streams

Include Library

#include <fstream>

Then open a file in write mode.

ofstream outfile;
outfile.open("xyz.dat");
outfile <<YOUR_OUTPUT<< endl;
outfile.close();